LEFT JOIN in LINQ to entities?

Ah, got it myselfs. The quirks and quarks of LINQ-2-entities. This looks most understandable: var query2 = ( from users in Repo.T_Benutzer from mappings in Repo.T_Benutzer_Benutzergruppen .Where(mapping => mapping.BEBG_BE == users.BE_ID).DefaultIfEmpty() from groups in Repo.T_Benutzergruppen .Where(gruppe => gruppe.ID == mappings.BEBG_BG).DefaultIfEmpty() //where users.BE_Name.Contains(keyword) // //|| mappings.BEBG_BE.Equals(666) //|| mappings.BEBG_BE == 666 //|| groups.Name.Contains(keyword) select new { UserId … Read more

Better way to query a page of data and get total count in entity framework 4.1?

The following query will get the count and page results in one trip to the database, but if you check the SQL in LINQPad, you’ll see that it’s not very pretty. I can only imagine what it would look like for a more complex query. var query = ctx.People.Where (p => p.Name.StartsWith(“A”)); var page = … Read more

How to set CommandTimeout for DbContext?

It will work with your method. Or subclass it (from msdn forum) public class YourContext : DbContext { public YourContext() : base(“YourConnectionString”) { // Get the ObjectContext related to this DbContext var objectContext = (this as IObjectContextAdapter).ObjectContext; // Sets the command timeout for all the commands objectContext.CommandTimeout = 120; } }

Why does the Contains() operator degrade Entity Framework’s performance so dramatically?

UPDATE: With the addition of InExpression in EF6, the performance of processing Enumerable.Contains improved dramatically. The approach described in this answer is no longer necessary. You are right that most of the time is spent processing the translation of the query. EF’s provider model doesn’t currently include an expression that represents an IN clause, therefore … Read more

The specified type member is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

You cannot use properties that are not mapped to a database column in a Where expression. You must build the expression based on mapped properties, like: var date = DateTime.Now.AddYears(-from); result = result.Where(p => date >= p.DOB); // you don’t need `AsQueryable()` here because result is an `IQueryable` anyway As a replacement for your not … Read more

EF Including Other Entities (Generic Repository pattern)

Use just the Include extension on IQueryable. It is available in EF 4.1 assembly. If you don’t want to reference that assembly in your upper layers create wrapper extension method in your data access assembly. Here you have example: public static IQueryable<T> IncludeMultiple<T>(this IQueryable<T> query, params Expression<Func<T, object>>[] includes) where T : class { if … Read more