linq-to-entities

Linq when using GroupBy, Include is not working

陌路散爱 提交于 2019-12-17 15:39:00
问题 include matchparticipants is not working. It always says Null when I debug. But when I put the GroupBy in comment it works fine. I am using Entity framework 4.3.1 with code-first. Entities: public class Match { [ScaffoldColumn(false)] public int MatchId { get; set; } [Required(ErrorMessage = "Matchtype is a required field")] public int Scheme { get; set; } [Required] [DefaultValue(false)] public bool Finished { get; set; } public int Round { get; set; } // Relations [Required] public Category

linq to entities vs linq to objects - are they the same?

不打扰是莪最后的温柔 提交于 2019-12-17 15:34:47
问题 I usually use the term entity to represent a business data object and in my mind, the linq to entities and linq to objects were the same. Is that not correct? 回答1: That is definitely not the case. LINQ-to-Objects is a set of extension methods on IEnumerable<T> that allow you to perform in-memory query operations on arbitrary sequences of objects. The methods accept simple delegates when necessary. LINQ-to-Entities is a LINQ provider that has a set of extension methods on IQueryable<T> . The

Linq to Entity Join table with multiple OR conditions

橙三吉。 提交于 2019-12-17 12:50:02
问题 I need to write a Linq-Entity state that can get the below SQL query SELECT RR.OrderId FROM dbo.TableOne RR JOIN dbo.TableTwo M ON RR.OrderedProductId = M.ProductID OR RR.SoldProductId= M.ProductID WHERE RR.StatusID IN ( 1, 4, 5, 6, 7 ) I am stuck with the below syntax int[] statusIds = new int[] { 1, 4, 5, 6, 7 }; using (Entities context = new Entities()) { var query = (from RR in context.TableOne join M in context.TableTwo on new { RR.OrderedProductId, RR.SoldProductId} equals new { M

LINQ To Entities + Include + Anonymous type issue

99封情书 提交于 2019-12-17 12:46:14
问题 Consider: Class Client Class Project Class Ticket Class Reply Clients have a sub collection of projects, projects have a sub collection of tickets and tickets have a sub collection of replies. var data = ctx.Set<Ticket>().Include(p => p.Client). Select(p => new { Ticket = p, LastReplyDate = p.Replies.Max(q => q.DateCreated)}); Doesn't work. Neither project nor client are loaded when selecting data this way. I know how to make it work. My question is why doesn't it work like this? 回答1: As

How to convert DbSet in Entity framework to ObjectQuery

假装没事ソ 提交于 2019-12-17 09:53:57
问题 I am using CodeFirst approach and struck with an issue where I need to convert DbSet to ObjectQuery. This is what I did for conversion. ObjectContext objectContext = ((IObjectContextAdapter)db).ObjectContext; ObjectSet<Request> objectSet = objectContext.CreateObjectSet<Request>(); where db is the context inheriting from DbContext and Request is class. So, when I try to call the method that expects ObjectQuery as ObjectQueryMethod(objectSet), it throws the following error. "Type of conditional

How to use SQL 'LIKE' with LINQ to Entities?

别来无恙 提交于 2019-12-17 09:38:14
问题 I have a textbox that allows a user to specify a search string, including wild cards, for example: Joh* *Johnson *mit* *ack*on Before using LINQ to Entities, I had a stored procedure which took that string as parameter and did: SELECT * FROM Table WHERE Name LIKE @searchTerm And then I would just do a String.Replace('*', '%') before passing it in. Now with LINQ to Entities I am trying to accomplish the same thing. I know there is StartsWith, EndsWith and Contains support, but it won't support

How do I perform Date Comparison in EF query?

纵饮孤独 提交于 2019-12-17 07:28:38
问题 Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query. Example: If I wanted all Employee names for those who started before today, I would do something like this in SQL: SELECT EmployeeNameColumn FROM EmployeeTable WHERE StartDateColumn.Date <= GETDATE() //Today But what about linq? DateTime startDT = //Today var EmployeeName = from e in db.employee where e.StartDateColumn <= startDT The above WHERE doesn't work: Exception Details: System

How do I perform Date Comparison in EF query?

北战南征 提交于 2019-12-17 07:28:12
问题 Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query. Example: If I wanted all Employee names for those who started before today, I would do something like this in SQL: SELECT EmployeeNameColumn FROM EmployeeTable WHERE StartDateColumn.Date <= GETDATE() //Today But what about linq? DateTime startDT = //Today var EmployeeName = from e in db.employee where e.StartDateColumn <= startDT The above WHERE doesn't work: Exception Details: System

The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 07:27:36
问题 public List<string> GetpathsById(List<long> id) { long[] aa = id.ToArray(); long x; List<string> paths = new List<string>(); for (int i = 0; i < id.Count; i++) { x = id[i]; Presentation press = context.Presentations.Where(m => m.PresId == aa[i]).FirstOrDefault(); paths.Add(press.FilePath); } return paths; } This code throws the following exception: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities. However, if I supply x instead of aa[i] it works. Why? 回答1: To

The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities

别来无恙 提交于 2019-12-17 07:27:28
问题 public List<string> GetpathsById(List<long> id) { long[] aa = id.ToArray(); long x; List<string> paths = new List<string>(); for (int i = 0; i < id.Count; i++) { x = id[i]; Presentation press = context.Presentations.Where(m => m.PresId == aa[i]).FirstOrDefault(); paths.Add(press.FilePath); } return paths; } This code throws the following exception: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities. However, if I supply x instead of aa[i] it works. Why? 回答1: To