background preloader

Ef4

Facebook Twitter

Entity Framework EF4 – (Értsük és) Tanuljuk meg!!! Agile Entity Framework 4 Repository Part 5: IObjectSet and Include. In Part 2 of this blog series, I created a context interface, IBAGAContext, that returns IObjectSet types rather than ObjectSet types from the EntitySets. Example: IObjectSet<Contact> Contacts{get;} IObjectSet<Customer> Customers {get;} IObjectSet is the new EF4 interface that is used to create the ObjectSets returned by the default context.

For a point of comparison, here’s a method from a default code generated context: public ObjectSet<Activity> Activities { get { if ((_Activities == null)) { _Activities = base.CreateObjectSet<Activity>("Activities"); } return _Activities; } } private ObjectSet<Activity> _Activities; EF4 LINQ Include(string) alternative to hard-coded string. Attaching and Detaching Objects. [This topic is pre-release documentation and is subject to change in future releases.

Attaching and Detaching Objects

Blank topics are included as placeholders.] In the Entity Framework, objects can be attached to or detached from an object context. Objects that are attached to an object context are tracked and managed by that object context. Detached objects are not referenced by the object context, and their resources can be reclaimed by the .NET Framework.

This topic describes how to attach and detach objects and some considerations for doing so. Attaching Objects Use one of the following methods to attach the object to an object context: Identity Resolution, State Management, and Change Tracking. Attaching Modified Entities in EF 4. Lately I’ve been working with EF 4.0 and finding that many of the new features are catching up with the features previously available in other framework like LINQ to SQL.

Attaching Modified Entities in EF 4

One example of this is the ability to easily attach objects (for example, disconnected objects that come in from another tier). For example, imagine you had a web service where a consumer submitted an object to get saved – you’d want to instantiate a new context, attach the incoming entity, and save the object. In previous versions of EF, this was not a trivial thing to do. However, this was always quite easy to do in LINQ to SQL by doing this: 1: using (var dataContext = new MyDataContext()) Generating Business Logic “Hooks” for EF4 Entities - system.data.objects dev guy. Once again a question in the EF MSDN Forum has prompted a blog post where I can give a more complete answer.

Generating Business Logic “Hooks” for EF4 Entities - system.data.objects dev guy

If I understand things correctly, the person asking the question wanted a simple way to add business logic hooks to their entities which would be called whenever they did SaveChanges. In EF4 we made available the basic building blocks for this kind of thing, but unfortunately it’s not quite as easy and discoverable as it ought to be. Since I’m stuck sitting at home with my knee elevated as I recover from minor knee surgery, I thought I’d take a little time today to create something which should make this much easier.

You can find the result here. Self Tracking Entities on the server side - MergeOption.NoTracking a viable solution? Thanks for replying, I appreciate you taking the time.

Self Tracking Entities on the server side - MergeOption.NoTracking a viable solution?

If you are on the server, I would rely on the object context to be responsible for changes. in your case, i think the delete is not recognized because, you are applying changes on an object context, from which it was retrieved from All of the STE functionality is of no consequence as long as the entity instance is connected to it's context, which is why calling MarkAsDeleted is basically a noop in the example.

You are right of course, that if I where to execute the save on a new context it should work, the only problem is that I would need to end the current unit of work and start a new one just before saving. Revisiting the Repository and Unit of Work Patterns with Entity Framework - Gil Fink on .Net. Change Management proxy. Building N-Tier Apps with EF4. This article is the third in a series about n-tier programming with the Entity Framework (see msdn.microsoft.com/magazine/dd882522.aspx and msdn.microsoft.com/magazine/ee321569.aspx), specifically about building custom Web services with the Entity Framework (EF) and Windows Communication Foundation (WCF).

Building N-Tier Apps with EF4

(In some situations, a REST-based service or some other approach is appropriate, but in these articles, I’ve focused on custom Web services.) The first article described a number of important design considerations and antipatterns. In the second article, I wrote about four patterns that can be used successfully in an n-tier application. That article also included code samples that illustrate how the first release of the Entity Framework (EF 3.5 SP1) can be used to implement what I call the Simple Entities pattern.

While Simple Entities is usually not the preferred pattern for n-tier applications, it is the most viable option in the first release of the EF. Self-Tracking Entities. Code-First Development with Entity Framework 4. .NET 4 ships with a much improved version of Entity Framework (EF) – a data access library that lives in the System.Data.Entity namespace.

Code-First Development with Entity Framework 4

When Entity Framework was first introduced with .NET 3.5 SP1, developers provided a lot of feedback on things they thought were incomplete with that first release. The SQL team did a good job of listening to this feedback, and really focused the EF that ships with .NET 4 on addressing it. Some of the big improvements in EF4 include: