linq-to-entities

Subquery with “ANY” and local array generate nested too deep SQL Statement

假如想象 提交于 2019-12-23 15:33:38
问题 public IEnumerable<Table1> GetMatchingTable1(string param, double[] Thicknesses) { return DBContext.Table1.Where(c => c.Field1 == param && Thicknesses.Any(Thickness => Thickness >= c.MinThickness && Thickness <= c.MaxThickness)) .ToList(); } Above query return the following exception. "Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries." So far, all my research on the web for this error pointed toward replacing "ANY" with "CONTAINS".

IEnumerable<T, int>, Arity and Generic Type Definitions

╄→尐↘猪︶ㄣ 提交于 2019-12-23 15:31:57
问题 I have a class Counter that counts things by key. Simplified: public class Counter<T> { private Dictionary<T, int> counts; public void Increment(T key) { int current; bool exists = counts.TryGetValue(key, out current); if (exists) { counts[key]++; } else { counts[key] = 1; } } } It does a number of other things specialized to my needs, but that's the essence. So far, it works great. Now I want to enable it to be used in a Linq query (with both the keys and the values). Do to that, I think I

Linq: Sort by Date when its stored as text

喜夏-厌秋 提交于 2019-12-23 11:54:55
问题 I need to sort by date but the date is stored as text in the database. I am using Linq to entities to perform queries. The way the database is designed it is not feasible to change the column to a date column because many different data types are in that column. There is a descriminator column named type so I will know what type a particular row is. 回答1: You can add a computed column to the table that will convert those strings to dates when your discriminator has a specific value (here I've

How to use Include and Anonymous Type in same query in Entity Framework?

穿精又带淫゛_ 提交于 2019-12-23 11:44:47
问题 In How To Count Associated Entities using Where In Entity Framework I get this query But when I access queryResult[0].post.Category or queryResult[0].post.Tags it´s always empty, because I am not using Include. Include dont work with Projection, as microsoft say at last item here: http://msdn.microsoft.com/en-us/library/bb896317.aspx var queryResult = (from post in posts join comment in comments.Where(x=> x.IsPublic) on post.Id equals comment.Post.Id into g select new { post, post.Author,

How to only load certain fields of a child object in Entity Framework 6.1?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 11:15:07
问题 I'm working on a model that has two classes, Product and Transaction . public class Product { [DataMember] public Guid ProductId {get; set;} [DataMember] public virtual ICollection<Transaction> Transactions { get; set; } } public class Transaction { [DataMember] public Guid TransactionId {get; set;} [DataMember] public DateTimeOffset Date { get; set; } [DataMember] public String Customer { get; set; } } How do I do a query that will retrieve a product and the Date of its transactions? I tried

How might I clean up this lambda?

守給你的承諾、 提交于 2019-12-23 10:25:23
问题 I have an expression that I use a few times in several LINQ queries so I separated it out into it's own method that returns the expression. The lambda portion of the function is kind of messy looking. Anyone want to take a crack at refactoring it and making it more readable and/or smaller? private Expression<Func<Message, bool>> UserSelector(string username, bool sent) { return x => ((sent ? x.FromUser : x.ToUser).Username.ToLower() == username.ToLower()) && (sent ? !x.SenderDeleted : !x

Order by descending based on condition

我怕爱的太早我们不能终老 提交于 2019-12-23 10:17:06
问题 I want to write a LINQ to Entity query which does order by ascending or descending based on input parameter, Is there any way for that. Following is the my code. Please suggest. public List<Hosters_HostingProviderDetail> GetPendingApproval(SortOrder sortOrder) { List<Hosters_HostingProviderDetail> returnList = new List<Hosters_HostingProviderDetail>(); int pendingStateId = Convert.ToInt32(State.Pending); //If the sort order is ascending if (sortOrder == SortOrder.ASC) { var hosters = from e

Distinct Date with Linq

ぃ、小莉子 提交于 2019-12-23 09:57:22
问题 I have an entity called Billings with a property of DateTime. I need to uniquely find the dates so I can go through them and do some stuff. I tried: var DistinctYearMonthsDays = (from t in db.Billings where t.DateTime.HasValue select t.DateTime.Value.Date).Distinct(); foreach (var day in DistinctYearMonthsDays) but I get (on the foreach ): The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

Is it possible to use Entity Framework without LINQ?

房东的猫 提交于 2019-12-23 09:20:16
问题 Is it possible to use Entity Framework without LINQ (linq to entities)? 回答1: It's not clear what you mean by using Linq to Entities and EF separately. That's a single library EntityFramework.dll . If you want to write queries on plain SQL, you can do it with SqlQuery() method of DbSet class: var users = context.Users.SqlQuery("SELECT * FROM dbo.Users").ToList(); In this case EF acts only as mapper, but it does not generates query. UPDATE According to your comments, you want to avoid

Linq to Entities group by week number

柔情痞子 提交于 2019-12-23 09:11:11
问题 I am using ASP.NET v4.5 and linq to entities I am trying to group my data by week using the below code var groupedByWeek = salesOrdersList .GroupBy(i => i.DueDate.AddDays(-(int)i.DueDate.DayOfWeek)); However I am getting a "yellow screen of death" with the error: LINQ to Entities does not recognize the method 'System.DateTime AddDays(Double)' method, and this method cannot be translated into a store expression. Ideally I would like to put var groupedByWeek = salesOrdersList.GroupBy(i => i