linq-to-entities

LINQ is Generating Extra IS NULL Condition in SQL Statement

本小妞迷上赌 提交于 2020-05-10 04:11:24
问题 I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query. My LINQ code is: if (email != null) { query = query.Where(r => r.Email == email); } The SQL condition generated from this is: (([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))) The ((

Linq to EF - Unsupported Functions

只谈情不闲聊 提交于 2020-04-28 17:51:53
问题 I'm making a query with Linq, backed by an Entity Framework datasource. I'm getting the following error: LINQ to Entities does not recognize the method 'Double Sqrt(Double)' method, and this method cannot be translated into a store expression. Here's a simplified version of my function (my version is more complex and uses ACos, sin, cos and other C# Math class functions). var objects = from n in context.Products.Where(p => p.r == r) let a = Math.Sqrt((double)n.Latitude) where a < 5 orderby a

Linq to EF - Unsupported Functions

℡╲_俬逩灬. 提交于 2020-04-28 17:43:40
问题 I'm making a query with Linq, backed by an Entity Framework datasource. I'm getting the following error: LINQ to Entities does not recognize the method 'Double Sqrt(Double)' method, and this method cannot be translated into a store expression. Here's a simplified version of my function (my version is more complex and uses ACos, sin, cos and other C# Math class functions). var objects = from n in context.Products.Where(p => p.r == r) let a = Math.Sqrt((double)n.Latitude) where a < 5 orderby a

Get common keys and common values of two dictionaries

ぃ、小莉子 提交于 2020-04-10 08:29:19
问题 Hi I have two dictionaries of next type: SortedDictionary<string, ClusterPatternCommonMetadata> PatternMetaData { get; set; } The ClusterPatternCommonMetadata object looks like: int ChunkQuantity { get; set; } SortedDictionary<int, int> ChunkOccurrences { get; set; } First I need the way to find keys of PatternMetaData that is exists in two dictionaries. I find this way: List<string> commonKeysString= vector.PatternMetaData.Keys.Intersect(currentFindingVector.PatternMetaData.Keys) Then I need

LINQ to Entities does not recognize the method 'System.DateTime GetValueOrDefault()'

给你一囗甜甜゛ 提交于 2020-04-07 21:56:13
问题 Struggling with very simple code that isn't working where similar code is working in other classes. It won't compile if I remove GetValueOrDefault(). Also I am using System.Linq. I'm getting this runtime error: LINQ to Entities does not recognize the method 'System.DateTime GetValueOrDefault()'. Any ideas? public List<AddressModel> GetAll(string customer_number) { addresses = (from a in db.ADDRESS where a.CUSTOMER_NUMBER.Equals(customer_number) select new AddressModel { Address_Id = a.ADDRESS

How to query every n-th value from an ordered set of entities?

空扰寡人 提交于 2020-03-25 16:12:55
问题 I would like to query an EF 4 entity set for every nth row, such that I get no more than x results. For example, given a set of 1000 names, give me every 100'th name (sorted by name of course) so that I would have 10 results. Is this kind of thing possible with LINQ to Entities, in any kind of efficient manner? 回答1: Not in L2S, but you could do this with ExecuteStoreQuery: You want SQL like: SELECT [Project1].[C1] AS [C1], [Project1].[DepartmentId] AS [DepartmentId], [Project1].[Code] AS

How to query every n-th value from an ordered set of entities?

﹥>﹥吖頭↗ 提交于 2020-03-25 16:11:41
问题 I would like to query an EF 4 entity set for every nth row, such that I get no more than x results. For example, given a set of 1000 names, give me every 100'th name (sorted by name of course) so that I would have 10 results. Is this kind of thing possible with LINQ to Entities, in any kind of efficient manner? 回答1: Not in L2S, but you could do this with ExecuteStoreQuery: You want SQL like: SELECT [Project1].[C1] AS [C1], [Project1].[DepartmentId] AS [DepartmentId], [Project1].[Code] AS

Get Dictionary value in IQueryable LINQ to Entities query

时间秒杀一切 提交于 2020-03-25 12:33:24
问题 I have to support multiple languages in production application. There are lot of Entity Framework queries that gets data from database as deferred IQueryable list like this: public IQueryable<Request> GetDeferredRequests() { return _dbContext.Set<Request>(); } POCO class looks like this: public partial class Request { public int RequestID { get; set; } public string StatusName { get; set; } public string RequestType { get; set; } } Data Transfer Object looks like this: public class RequestDTO

Select a two-way table in MySql

时间秒杀一切 提交于 2020-03-05 07:35:53
问题 I have three MySql tables: Students - StudentId, StudentName Assessments - AssessmentId, AssessmentName Results - StudentId, AssessmentId, Grade I can't predetermine the number of students or assessments, as these are created by users. How can I select a two-way table, showing the results of all students' assessments (which will have an unpredetermined number of rows and columns): |--------|---------|---------|---------|---------|---------| |User |Test A |Test B |Test C |Test D |Test E | |---

Select a two-way table in MySql

安稳与你 提交于 2020-03-05 07:35:09
问题 I have three MySql tables: Students - StudentId, StudentName Assessments - AssessmentId, AssessmentName Results - StudentId, AssessmentId, Grade I can't predetermine the number of students or assessments, as these are created by users. How can I select a two-way table, showing the results of all students' assessments (which will have an unpredetermined number of rows and columns): |--------|---------|---------|---------|---------|---------| |User |Test A |Test B |Test C |Test D |Test E | |---