Browse by Tags

All Tags » Entity Framework (EF) » .Net (RSS)

EF: why Include method is an anti-pattern IMHO? Part 5: many to many relationships

I recently blogged to explain why I found that Include method is an anti-pattern IMHO. EF: Why Include method is an anti-pattern IMHO? EF: Why Include method is an anti-pattern IMHO even with many to one navigation properties? 2/3 EF: Why Include method...

EF: Why Include method is an anti-pattern IMHO? Conclusion

First, I admit that Anti-pattern word was excessive but I see so many catastrophic performances in my audits where developers use Include method. I presented you a very « special » way to realize Include. If you use Include ONLY on the one side, performance...
Posted by Matthieu MEZIL | with no comments

EF: Why Include method is an anti-pattern IMHO? 3/3

I will continue on my sample with Contoso. I won’t use a Repository and I will directly querying my DB on my ViewModel. The main reason is because it is easier for demo and because the main topic is the Include method. I will use Include method with the...

EF: Why Include method is an anti-pattern IMHO even with many to one navigation properties? 2/3

In my yesterday post , I explained why I think Include method is an anti-pattern. Darrel commented that the issue was because I use Include with one to many navigation property on many side. In the sample, I have only one Include to side many and four...

EF: Why Include method is an anti-pattern IMHO?

On different session I saw, eager loading with Include method is presented as a good pattern. However, IMHO, it’s an anti-pattern. That’s right, Include method like lazy loading is very easy to use. But performance with these is often very bad or even...

EF and recursion

Through this post, I will show you a concrete case of a bad EF usage I recently saw. My model is the following: We want to get a tree with a constraint: if the node type is "G" and the node doesn’t have any child, it should not be present on...
Posted by Matthieu MEZIL | with no comments

L2E: SQL impact

As I wrote yesterday , “Behind the EF magic, there is the SQL reality. I’m sticking to my guns, if you don’t know SQL, you can’t write best Entity Framework queries. I find a good sample with grouping functions.” Yesterday, I showed you how to have a...

How to get many grouping functions in only one query with LINQ?

Behind the EF magic, there is the SQL reality. I’m sticking to my guns, if you don’t know SQL, you can’t write best Entity Framework queries. I find a good sample with grouping functions. Imagine that you want to get the last order date and the number...

Self Tracking Entities performance

I have two tables: Books and Authors. Books: Id (int, PK) Title (nvarchar) AuthorId (int, FK) Authors: Id (int, PK) Name (nvarchar) I have 10,000 books, all on the first author. // Julie, you have to write a lot of versions of Programming Entity Framework...

WCF RIA Services: conflict resolution

With Entity Framework, you can use default behavior to solve concurrent access: last writes wins. You can also choose that EF throws an exception if DB has been changed by another user. With RIA Services, if you choose this second solution, you can fix...

Generate your WCF Service from your edmx using T4

One year ago, I wrote T4 templates in order to generate WCF Service from edmx using T4. I presented it in last MS France TechDays and MVP Summit. However, I didn’t take time to think about what I wanted to do with it. Moreover, I wrote them with the EF...

Why using Entity Framework?

In this post, we will use a sample and we will study its implementation with DataReader / LINQ To SQL / Entity Framework. In this sample, we will use the following database : The method I want to code has to return the best 10 members   (order by...

WCF RIA Services: don’t forget EF best practices!

To include related entities, we need to add Include attribute in metadata. (Thanks Audrey :)) Then we can use something like this: public   IQueryable < Customer > GetCustomers() {     return   this .ObjectContext.Customers;...

EDM mapping: How to use Horizontal Entity Splitting

One of the reasons why I love so much Entity Framework is the mapping. Many developers ignore how powerful EF mapping is. I just remind them that I realized some videos on it . Some scenarios are often very useful but some are less frequent. Horizontal...

DTO <—> Entity Types conversion

Sometimes, we have to work with DTO very similar than our entities. I wrote this class to make the conversion. ///   <summary> /// Extension methods to convert an EntityType to a DTO and reversely ///   </summary> public   static...

Entity Framework: Be vigilant with Include method!

Include method is very easy to use and it’s great. But its implementation is not always the best one. Why? The Include method allows you to get entity graph with only one SQL query. The idea is excellent but… The problem is that to do it, EF has to do...

Entity Framework 4 and MutiResultSet, execute multiple queries on only one DB access

In the EFExtensions project , we have an illustration of the use of MutiResultset with EF which is a good idea. However, this is used only with Stored Procedure. Moreover, contrary to what is done on it, I don’t want to specify the mapping when I already...

How to include recursion / table valued functions in LINQ To Entities queries with EF4? v2

I posted a first version on this topic few days ago . However, the Regex pattern wasn’t perfect because it didn’t support every case (join on table valued functions for example was not supported). Moreover, with ExecuteStoreQuery method, properties and...
Posted by Matthieu MEZIL | with no comments

How to include recursion / table valued functions in LINQ To Entities queries with EF4?

In this post, we use Northwind DB with this EDM:   I want to get all orders for an employee or his sub-employees in only one T-SQL query. Recursion with T-SQL => CTE. The problem is the fact that EF4 doesn’t support recursion. I found an interesting...

Bulk delete v4

In my previous post , I realized a Proof Of Concept to validate Bulk Delete feasibility for each mapping scenarios. Danny found a bug in SaveChanges method:        public   override   int SaveChanges( SaveOptions...
More Posts Next page »