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

Using contains() in LINQ to SQL

Looking at the other attempts saddens me 🙁 public IQueryable<Part> SearchForParts(string[] query) { var q = db.Parts.AsQueryable(); foreach (var qs in query) { var likestr = string.Format(“%{0}%”, qs); q = q.Where(x => SqlMethods.Like(x.partName, likestr)); } return q; } Assumptions: partName looks like: “ABC 123 XYZ” query is { “ABC”, “123”, “XY” }

Update using LINQ to SQL

LINQ is a query tool (Q = Query) – so there is no magic LINQ way to update just the single row, except through the (object-oriented) data-context (in the case of LINQ-to-SQL). To update data, you need to fetch it out, update the record, and submit the changes: using(var ctx = new FooContext()) { var … Read more