EF 5 Changing Connection String at Runtime
Use the context constructor overload that takes the connection string as a parameter.
Use the context constructor overload that takes the connection string as a parameter.
The easiest way with DbContext and DbSet<T> is just to use ToString() on the IQueryable you have built. For example: var query = context.Blogs.Include(b => b.Posts) .Where(b => b.Title == “AnyTitle”); string sql = query.ToString(); sql contains the SQL command which will be issued to the DB when the query gets executed.
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
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
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
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” />
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/
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
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
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