Entity Framework .Where method chaining

They should both produce the same end result (if I’m not mistaken) but I find the the second is more readable and better shows the original intent. Update I just verified the above statement using LINQPad. Both queries will, in fact, product the same SQL. For example: context.SomeTable.Where(c => c.ParentId == null) .Where(c => c.Name.Contains(“F”)) … Read more

AutomaticMigrationsEnabled false or true?

Automatic migrations do all the magic for you but they don’t allow strict versioning (you don’t have special fixed migration for each version). Without strict versioning you cannot track version of your database and you cannot do explicit upgrades (you cannot do downgrades at all). If you don’t plan to use versioning where you need … Read more

Expression cannot contain lambda expressions

Evaluating Lambda expressions in debugger (watch window) is not supported yet. Theres an open feature request for it. For debugging your problem you should assign the result of the lambda expression to a dedicated variable and use that in following statements. var entity = entityvDetails.Where(e => e.sad_id == item.sad_id).FirstOrDefault(); Update 08/2014: Microsoft posted an update … Read more

Multiple SaveChanges calls in entity framework

I know it’s kind of late answer but i found it useful to share. Now in EF6 it’s easier to achieve this by using dbContext.Database.BeginTransaction() like this : using (var context = new BloggingContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { // do your changes context.SaveChanges(); // do another changes context.SaveChanges(); dbContextTransaction.Commit(); } … Read more

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

Why re-initiate the DbContext when using the Entity Framework?

Managing Lifetime You’re correct that a single static instance of DbContext is usually not recommended: The more you use an ObjectContext, generally the bigger it gets. This is because it holds a reference to all the Entities it has ever known about, essentially whatever you have queried, added or attached. So you should reconsider sharing … Read more

Entity Framework Code First naming conventions – back to plural table names?

The RTM version of Code First will fully support a cool feature called Pluggable Conventions where you can add or replace the default conventions such as the one you mentioned. Fortunately, what you are looking for is already included in CTP5. You can switch off the pluralizing table names convention with removing PluralizingTableNameConvention convention. This … Read more

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