Posts

Showing posts with the label EntityFramework

Entity Framework: ToListAynsc & WhereAsync

When upgrading aspnet mvc applications I like to take a look on how I can convert the api's to async. This sometimes is really easy but as things get more complex my queries do as well. So this is a list of ways you can form a where clause on top your  async  but note not all solutions take advantage of it. Notes on EFCore Entity Framework Core provides a set of asynchronous extension methods that can be used as an alternative to the LINQ methods that cause a query to be executed and results returned. Examples include  ToListAsync() ,  ToArrayAsync() ,  SingleAsync() , etc. There are not async versions of LINQ operators such as  Where(...) ,  OrderBy(...) , etc. because these methods only build up the LINQ expression tree and do not cause the query to be executed in the database. https://codereview.stackexchange.com/questions/32160/filtering-a-collection-by-an-async-result Filtering a collection by an async result ,  built an extension method called WhereAsync. publ

EF6 Cheatsheet

Image
When I was first learning EF I tried using model first however migrations and the setup to handle it was too buggy. I'm sure I could have gotten it in time but I've learned right way the importance of being a good dba. Performance Considerations for EF 4, 5, and 6 Entity Framework - Entity Framework 6: The Ninja Edition Best practices to improve Entity Framework performance | InfoWorld Tips to improve Entity Framework Performance EntityFramework Performance and AutoDetectChanges RoleEntryPoint Class (Microsoft.WindowsAzure.ServiceRuntime) <sessionState> Element using Statement (C# Reference) More coming soon

EF: The database cannot be opened because it is version 782

    The full error message for this is "The database cannot be opened because it is version 782. This server supports version 706 and earlier. A downgrade path is not supported" and started appearing for me when I upgraded to Visual Studio 2015 Community. Originally I created a database file in visual studio 2013. <add name="ProductContext" connectionString="Data Source= (LocalDb)\v11.0 ;AttachDbFilename=|DataDirectory|\ProductContext.mdf;Initial Catalog=ProductContext;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="ProductContext" connectionString="Data Source= (LocalDB)\MSSQLLocalDB ;AttachDbFilename=|DataDirectory|\ProductContext.mdf;Initial Catalog=ProductContext;Integrated Security=True" providerName="System.Data.SqlClient" /> Notes I did not have to delete the local database files and have to start over, thankfully it was a small change. Resource http://sqlser

Entity Framework 6: Pull in Child Entities with Async WebAPI 2.0

    Just a quick piece of code to get all the children under a given parent. The solutions is pretty straight forward but took sometime to think about since I wanted to keep the result asynchronous. I was also thinking of how I would use scaffolds creates other apis with my models. Code: db . Product . Include(x => x . ProductChildren) . SingleOrDefaultAsync(x  =>  x . Id  ==  id); Notes:     Its late at nite (so no judging...) but I wanted to get my thoughts down and explore this code for a bit. The piece code is async but my question is does it pull the child entities after it has filter down on the parent id? Or does it pulls in all the children before it has filtered down on a particular partent id and if not wouldn't a more proper way to do it be more something like... db . Product . FindAsync(id).Include(x => x . ProductChildren); This code doesn't work of course, since the Include doesn't exist for 'FindAsync' but either way alternative

Using Entity Framework and a Storage Procedure with Parameters

    So I was stuck sometime ago on a problem I had where I was using my sql store procedure with the Entity Framework. Eventually found what I needed and the purpose of this article is just to write out a small example. I've come up with  multiple  ways to achieve the same thing now but this is the most basic form of it. public IList<KeyValuePair> GetIds (string id) { using (var db = DBFactory. GetDB ()) { return db.Database.SqlQuery<KeyValuePair>( "EXEC db.MyDatabase @id", new SqlParameter("id", id)); } } Resources How to pass parameters to DbSet.SqlQuery Method in Entity Framework How to use DbContext.Database.SqlQuery (sql, params) with stored procedure? EF Code First CTP5 The data reader has more than one field. Multiple fields are not valid for EDM primitive types KeyValuePair(TKey, TValue) Structure (System.Collections.Generic)

Popular posts from this blog

UI-Bootstrap Collapsible Sticky Footer

Installing Windows on Acer chromebook 15 cb3-532

Aspetcore: NLog with Postgresql