Keeping track of interesting places I put my feet on in the software development world.
Search This Blog
Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts
Thursday, July 7, 2016
Dealing with EF Connection Timeouts/Connection lost issues using Connection Resilience/Retry Logic built in support (EF onwards)
Upon facing connection timeouts/connection lost issues in working with EF, instead of trying brute force methods such as wrapping your connection instance in a for statement or alike, the best practice is to use Connection Resilience/Retry Logic (EF onwards) support, which provides more sophisticated retry strategy implementations, shipped in.
Sunday, July 3, 2016
Adding objects from different schemas using Entity Framework with Oracle
At first, it looked like there was is no Entity Framework support to adding objects (say, tables) created in schemas other than the one used in the database connection.
But turned out it is possible. Stackoverflow will list some "workarounds" , but there is no need to - because SO lists one post that gives the exact solution for this problem, and it looks great.
Summarizing it:
You can either add more schemas under which search for objects to add during the creation of the Ado.net object (while adding the connection) - or by modifying the existing connection in the Server Explorer in Visual Studio.
If you are adding the ADO.NET object, you need the connection definition window above - and if you already have your ADO.NET object there, go to Visual Studio -> View -> Server Explorer, search for the desired connection under Data Connections and right click it. Then choose Modify. You will get the window above.
The steps to follow are:
But turned out it is possible. Stackoverflow will list some "workarounds" , but there is no need to - because SO lists one post that gives the exact solution for this problem, and it looks great.
Summarizing it:
You can either add more schemas under which search for objects to add during the creation of the Ado.net object (while adding the connection) - or by modifying the existing connection in the Server Explorer in Visual Studio.
If you are adding the ADO.NET object, you need the connection definition window above - and if you already have your ADO.NET object there, go to Visual Studio -> View -> Server Explorer, search for the desired connection under Data Connections and right click it. Then choose Modify. You will get the window above.
The steps to follow are:
- Select the Filter tab
- Click the 3 dots singled out, and add the schemas you want to be included by EF when searching for objects to add to the model.
- After you are done with step 1, click the Update button singled out in the screenshot.
That's it. You can right click your edmx file, click Update Model From Database, and you will now have, under Tables, the tables listed by their schema.
Sunday, May 22, 2016
Improving performance in working with EF
I stumbled across a SO post about performance, where the main hindrance was Entity Framwork/DB operations.
Here's a summary of the suggested approaches for performance improvement:
- Using Dapper or raw ADO.NET components.
- Disabling EF change auto detection and validation on save flags.
- Using BulkInsert
- Instead of adding new entities inside a loop, collect all the entity objects to be added into a collection - and one you are finished issue a single [entity].AddRange(collection) to push all the new entities into the EF object (and afterwards performing a SaveChanges). It is stated that this is performance-wiser.
Some performance comparison tests for the above can be found in the web, here is a nicely presented one.
See also Performance considerations for EF 4, 5 and 6.
Thursday, November 12, 2015
Project will not build after adding function or procedure to edmx
Having issues in trying to add a function/procedure to your Entity Data Model - it will not build after that ?
What's more, it works perfectly with Entity Framework version 5 ? And with 6, which you are trying now, does not ?
Well, here's the solution.
Lessons learned: there is such a thing as Entity Framework Tools for Visual Studio, and we need to make sure we have it updated/in sync with the version of Visual Studio we are using in combination with a package we have just downloaded/added to our project.
Dependencies, dependencies, dependencies...
What's more, it works perfectly with Entity Framework version 5 ? And with 6, which you are trying now, does not ?
Well, here's the solution.
Lessons learned: there is such a thing as Entity Framework Tools for Visual Studio, and we need to make sure we have it updated/in sync with the version of Visual Studio we are using in combination with a package we have just downloaded/added to our project.
Dependencies, dependencies, dependencies...
Sunday, August 30, 2015
Extension Method to Flatten Entity Framework Validations Errors - providing Entity, Property and Error message
public static class ExtensionMethods
{
public static List FlattenErrors(this DbContext dbContext)
{
return dbContext
.GetValidationErrors()
.SelectMany(e =>
e.ValidationErrors
.Select(ve =>
string.Format("Entity: [{0}], Property: [{1}], Error: [{2}].", ObjectContext.GetObjectType(e.Entry.Entity.GetType()).Name, ve.PropertyName, ve.ErrorMessage)
))
.ToList();
}
}
Subscribe to:
Posts (Atom)