Search

Tutorials, tips&tricks, snippets..

#KISS: KEEP IT SIMPLE, STUPID!

Category

Entity Framework

Modify Entity Framework timeout

As the title said, here the snippet:

using (var db = new AccessData.Entities())
{
    ((IObjectContextAdapter)db).ObjectContext.CommandTimeout = 180;
    .......
}
Advertisements

No connection string named ‘MyEntities’ could be found in the application config file

This error occurs when you haven’t set the correct value in your config or when you have one project calling another project. How? Why? Let’s see the details!

Continue reading “No connection string named ‘MyEntities’ could be found in the application config file”

Entity Framework 6: audit / track changes

Entity Framework is very powerful. It takes care of the dirty jobs and it makes your programmer’s life easier. A very useful feature you can use is override the saveChanges method, for example, to audit/track the changes made.

Continue reading “Entity Framework 6: audit / track changes”

How to see executed sql code within entity framework

If you want to track what entity framework (6.0 or more) is doing, you can convert your actions in sql code.

What you have to do is:

using (var db = new AccessData.Entities())
{
//logger: is a function to write output in a file txt
db.Database.Log = s => Utility.Logger(s);
//example
var list = db.myTable.Where( x => x.NOME = "piero");
//you will find in your txt file the sql code of the
//operation above (SELECT * FROM myTable where NOME="piero");
}

Note: For those using Entity Framework 6 and up, if you want to view the output SQL in Visual Studio (like I did) you have to use the new logging/interception functionality. More infos here.

Entity Framework: There is already an open DataReader associated with this Command which must be closed first.

This can be one of the most boring error to fix within Entity Framework code, but, once you know this trick, it will be very easy!
Continue reading “Entity Framework: There is already an open DataReader associated with this Command which must be closed first.”

Powered by WordPress.com.

Up ↑