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

Attaching and detaching entities from context correctly in EF4.1

IEntityWithKey is interface for other types of entities. It is for “big” entities. For example EntityObject implement this interface. These entities are not considered as POCO and are not supported by DbContext API. If you want to use IEntityWithKey your classes must implement it – it is not something that would happen automatically. Correct attaching … Read more

Entity Framework creates foreign key objects instead of using those that are already available

If you don’t use the same context instance to load related entities you cannot simply add them to the new entity and expect that existing records in the database will be used. The new context doesn’t know that these instances exist in the database – you must to say it to the context. Solutions: Use … Read more

Entity Framework Code First and Connection String Issue

For EF Code First you can use ordinary connection string if you are using SQL Server. <add name=”DataContext” connectionString=”Data Source=myserver.com;Initial Catalog=MyDataBase;Persist Security Info=True;User ID=username;Password=password” providerName=”System.Data.SqlClient” />

Turn off EF change tracking for any instance of the context [duplicate]

Try changing your context constructor to this: public ReportingContext() { this.Configuration.AutoDetectChangesEnabled = false; } EDIT: This will after all not help you, as stated on Arthur’s blog, it is usable only in particular scenarios: http://blog.oneunicorn.com/2012/03/12/secrets-of-detectchanges-part-3-switching-off-automatic-detectchanges/

mapping multiple tables to a single entity class in entity framework

You can use Entity Splitting to achieve this if you have the same primary key in both tables. modelBuilder.Entity<TestResult>() .Map(m => { m.Properties(t => new { t.Name, t.Text, t.Units /*other props*/ }); m.ToTable(“Result”); }) .Map(m => { m.Properties(t => new { t.Status, t.Analysis /*other props*/}); m.ToTable(“Test”); }); Here’s a useful article

Enums with EF code-first – standard method to seeding DB and then using?

Unfortunately, enums are not natively supported on EF 4.1. Here’s one rather known article on how to deal with them: Faking enums on EF 4. It does, however, require a wrapper. There’s a simpler way to map enums in EF 4 however: just create an int property on your class to represent the int value … Read more

Importing SQL Server’s CONTAINS() as a model defined function

The function you have defined above uses Entity SQL, not Transact SQL, so I think the first step is to figure out whether CONTAINS(*,’text’) can be expressed in Entity SQL. Entity SQL doesn’t support the * operator as described here: http://msdn.microsoft.com/en-us/library/bb738573.aspx and if I try entities.CreateQuery<TABLE_NAME>(“select value t from TABLE_NAME as t where CONTAINS(*, ‘text’)”); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)