Why does DbSet.Add work so slow?

I’ve got interesting performance testing results and I’ve found a culprit. I have not seen any information like this in any EF source I’ve ever read. It turns out to be Equals overridden in a base class. The base class supposed to contain Id property shared between all types of concrete entities. This approach recommended … Read more

Explanation of POCO

Instead of calling them POCOs, I prefer to call them persistence ignorant objects. Because their job is simple, they don’t need to care about what they are being used for or how they are being used. Personally I think POCOs are just another buzzword (like Web 2.0 – don’t get me started on that) for … Read more

what is Entity Framework with POCO

POCO stands for “Plain Old C# Object” or “Plain Old CLR Object”, depending on who you ask. If a framework or API states that it operates on POCO’s, it means it allows you to define your object model idiomatically without having to make your objects inherit from specific base classes. Generally speaking, frameworks that work … Read more

How to fix: The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical?

The reason for the error are incorrectly configured relations in your model. This is not correct: one.HasRequired(t => t.Two) .WithMany(s => s.Ones) .HasForeignKey(t => t.TwoId); one.HasRequired(t => t.Three) .WithMany(s => s.Ones) .HasForeignKey(t => t.ThreeId); It should be: one.HasRequired(t => t.Two) .WithMany(s => s.Ones) .HasForeignKey(t => new { t.TwoId, t.ThreeId }); Because dependent’s FK must contain … 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

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

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