keyword not supported data source

What you have is a valid ADO.NET connection string – but it’s NOT a valid Entity Framework connection string. The EF connection string would look something like this: <connectionStrings> <add name=”NorthwindEntities” connectionString= “metadata=.\Northwind.csdl|.\Northwind.ssdl|.\Northwind.msl; provider=System.Data.SqlClient; provider connection string=&quot;Data Source=SERVER\SQL2000;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=False&quot;” providerName=”System.Data.EntityClient” /> </connectionStrings> You’re missing all the metadata= and providerName= elements in your EF connection … Read more

LINQ to Entities does not recognize the method ‘System.String Format(System.String, System.Object, System.Object)’

Entity Framework is trying to execute your projection on the SQL side, where there is no equivalent to string.Format. Use AsEnumerable() to force evaluation of that part with Linq to Objects. Based on the previous answer I have given you I would restructure your query like this: int statusReceived = (int)InvoiceStatuses.Received; var areaIds = user.Areas.Select(x=> … Read more

How do I apply OrderBy on an IQueryable using a string column name within a generic extension method?

We did something similar (not 100% the same, but similar) in a LINQ to SQL project. Here’s the code: public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering, params object[] values) { var type = typeof(T); var property = type.GetProperty(ordering); var parameter = Expression.Parameter(type, “p”); var propertyAccess = Expression.MakeMemberAccess(parameter, property); var orderByExp = Expression.Lambda(propertyAccess, parameter); MethodCallExpression … Read more

When should I call SaveChanges() when creating 1000’s of Entity Framework objects? (like during an import)

I would test it first to be sure. Performance doesn’t have to be that bad. If you need to enter all rows in one transaction, call it after all of AddToClassName class. If rows can be entered independently, save changes after every row. Database consistence is important. Second option I don’t like. It would be … Read more

Method cannot be translated into a store expression

Reason: By design, LINQ to Entities requires the whole LINQ query expression to be translated to a server query. Only a few uncorrelated subexpressions (expressions in the query that do not depend on the results from the server) are evaluated on the client before the query is translated. Arbitrary method invocations that do not have … Read more

select top 5 in entity framework

Try this: var items = context.PersonSet.OrderByDescending(u => u.OnlineAccounts.Count).Take(5); This returns IQueryable<Person>. It doesn’t return results yet, because it implements deferred execution. It will be translated to SQL and executed when needed: var metarializedItems = items.ToList(); // ToList forces execution or foreach(var item in items) // foreach forces execution Example above will translate to SQL similar … Read more