LINQ to Entities does not recognize the method ‘System.TimeSpan Subtract(System.DateTime)’ method

You could use the EntityFunctions.DiffDays method EntityFunctions.DiffDays(product.EventDate, DateTime.Now) //this will return the difference in days UPDATE EntityFunctions is now obsolete so you should use DBFunctions instead. System.Data.Entity.DbFunctions.DiffDays(product.EventDate, DateTime.Now)

How to move from Linq 2 SQL to Linq 2 Entities?

To show the created SQL commands for debugging in EF using System.Data.Objects; … var sqlQuery = query as ObjectQuery<T>; var sqlTrace = sqlQuery.ToTraceString(); AFAIK there are no commands to create DB’s or do any sort of DDL work. This is design limitation of the “Entity SQL” language The EDMX design surface will map your current … Read more

What is the purpose of .edmx files?

EDMX is Visual Studio’s “container” for all things about your Entity Data Model. It contains all the information that is in the CSDL, SSDL, MSL, plus information about the visual layout of the tables in your Visual Studio designer surface. The EDMX file is converted into CSDL, SSDL, MSL (typically embedded as resources in your … Read more

Updating your edmx to reflect changes made in your db (.net linq-to-entities)

Update/delete from the EDMX is not always functional. If the model doesn’t get updated on clicking Update Model from Database let’s say when you have updated a view/table in the DB, do the following: 1) Delete the view/table from the model diagram 2) Switch the EDMX to xml view (right click the edmx file and … Read more

How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()

You want to use the .Include(string) method references in this “Shaping query results” article. var item = from InventoryItem item in db.Inventory.Include(“ItemTypeReference”).Include(“OrderLineItems”) where item.ID == id select item; There is probably a “sql” style syntax for the Includes as well. Also see this article about moving from LINQ-to-SQL to LINQ-to-Entities. For others looking for a … Read more

Entity Framework: Querying Child Entities [duplicate]

The only way to get a collection of parents with a filtered children collection in a single database roundtrip is using a projection. It is not possible to use eager loading (Include) because it doesn’t support filtering, Include always loads the whole collection. The explicite loading way shown by @Daz requires one roundtrip per parent … Read more

Linq int to string

With EF v4 you can use SqlFunctions.StringConvert. So your code would end looking like this: from s in ctx.Services where SqlFunctions.StringConvert((double)s.Code).StartsWith(“1”) select s EDIT As Rick mentions in his comment, the reason for casting the int to a double (decimal probably works too) is that the function does not have an overload for int.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)