Entity Framework initialization is SLOW — what can I do to bootstrap it faster?

In pre EF6 view generation is known to be slow for bigger models. For now the solution is to use pregenerated views. This way you generate views at design time and are avoiding this work at runtime. To do that download EF power tools and select “Optimize Entity Data Model”. It will add a C# … Read more

Map two different entities to the same table?

You can’t map two regular entities into same table. You have several choices: Use table splitting. Use custom query with projection to non entity type (as @Aducci proposed) Use QueryView Use database view or directly DefiningQuery Table splitting Table splitting allows you to map a table into two entities in 1:1 relation. First entity will … Read more

Using Include in Entity Framework 4 with lambda expressions

The RTM version of Entity Framework 4.1 actually includes extension methods in the EntityFramework.dll file, for eager loading with lambda through the Include function. Just include the DLL in your project and you should be able to write code like: var princesses1 = context.Princesses.Include(p => p.Unicorns).ToList(); Remember to add an Import/Using statement to include the … Read more

The object ‘DF__*’ is dependent on column ‘*’ – Changing int to double

Try this: Remove the constraint DF_Movies_Rating__48CFD27E before changing your field type. The constraint is typically created automatically by the DBMS (SQL Server). To see the constraint associated with the table, expand the table attributes in Object explorer, followed by the category Constraints as shown below: You must remove the constraint before changing the field type.

ASP.NET MVC / EF4 / POCO / Repository – How to Update Relationships?

I’ve accepted @jfar’s answer because he put me on the right track, but thought i’d add an answer here for other people’s benefit. The reason the relationships were not getting updated is for the following reasons: 1) Completely disconnected scenario. ASP.NET = stateless, new context newed up each HTTP request. 2) Edited entity created by … Read more

Querying objects after AddObject before SaveChanges?

To persist an entity you usually add it to it’s DbSet in the context. For example var bar = new Bar(); bar.Name = “foo”; var context = new Context(); context.Bars.Add(bar); Surprisingly, querying context.Bars, the just added entity cannot be found var howMany = context.Bars.Count(b => b.Name == “foo”); // howMany == 0 After context.SaveChanges() the … Read more

tech