Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos

This answer comes ‘a bit’ late as I’ve just faced the same issue with EF4 POCO proxies. I solved it using a custom converter that calls Mapper.DynamicMap<TDestination>(object source) to invoke the runtime type conversion, rather than the .Include<TOtherSource, TOtherDestinatio>(). It works fine for me. In your case you would define the following converter: class PaymentConverter … Read more

Entity Framework loading child collection with sort order

You cannot achieve it directly because neither eager or lazy loading in EF supports ordering or filtering. Your options are: Sort data in your application after you load them from database Execute separate query to load child records. Once you use separate query you can use OrderBy The second option can be used with explicit … Read more

Generate POCO classes in different project to the project with Entity Framework model

Actually the T4 templates in EF 4.0 were designed with this scenario in mind 🙂 There are 2 templates: One for the Entities themselves (i.e. ModelName.tt) One for the ObjectContext (i.e. ModelName.Context.tt) You should put the ModelName.tt file in you POCO project, and just change the template to point to the EDMX file in the … Read more

Why is my Entity Framework Code First proxy collection null and why can’t I set it?

As you correctly observed in the answer to your own question, removing the “virtual” keyword from the collection properties works around the problem, by preventing the Entity Framework from creating a change tracking proxy. However, this is not a solution for many people, because change tracking proxies can be really convenient and can help prevent … Read more

Using JsonConvert.DeserializeObject to deserialize Json to a C# POCO class

Here is a working example. Keypoints are: Declaration of Accounts Use of JsonProperty attribute . using (WebClient wc = new WebClient()) { var json = wc.DownloadString(“http://coderwall.com/mdeiters.json”); var user = JsonConvert.DeserializeObject<User>(json); } – public class User { /// <summary> /// A User’s username. eg: “sergiotapia, mrkibbles, matumbo” /// </summary> [JsonProperty(“username”)] public string Username { get; set; … Read more

What is POCO in Entity Framework? [closed]

POCOs(Plain old CLR objects) are simply entities of your Domain. Normally when we use entity framework the entities are generated automatically for you. This is great but unfortunately these entities are interspersed with database access functionality which is clearly against the SOC (Separation of concern). POCOs are simple entities without any data access functionality but … Read more

Update relationships when saving changes of EF4 POCO objects

Let’s try it this way: Attach BlogPost to context. After attaching object to context the state of the object, all related objects and all relations is set to Unchanged. Use context.ObjectStateManager.ChangeObjectState to set your BlogPost to Modified Iterate through Tag collection Use context.ObjectStateManager.ChangeRelationshipState to set state for relation between current Tag and BlogPost. SaveChanges Edit: … Read more