linq-to-entities

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties

ぃ、小莉子 提交于 2019-12-17 05:38:22
问题 Using this code in Entity Framework I receive the following error. I need to get all the rows for a specific date, DateTimeStart is of type DataType in this format 2013-01-30 12:00:00.000 Code: var eventsCustom = eventCustomRepository.FindAllEventsCustomByUniqueStudentReference(userDevice.UniqueStudentReference) .Where(x => x.DateTimeStart.Date == currentDateTime.Date); Error: base {System.SystemException} = {"The specified type member 'Date' is not supported in LINQ to Entities. Only

linq to entities doesn't recognize a method

偶尔善良 提交于 2019-12-17 05:13:20
问题 I have those methods: public int count( Guid companyId, Expression<Func<T, bool>> isMatch) { var filters = new Expression<Func<T, bool>>[]{ x => x.PriceDefinition.CompanyId == companyId, isMatch }; return GetCount(filters); } public virtual int GetCount( IEnumerable<Expression<Func<T, bool>>> filters) { IQueryable<T> _query = ObjectSet; if (filters != null) { foreach (var filter in filters) { _query = _query.Where(filter); } } return _query.Count(); } When using: count(some_guid, x => x

linq to entities doesn't recognize a method

↘锁芯ラ 提交于 2019-12-17 05:13:15
问题 I have those methods: public int count( Guid companyId, Expression<Func<T, bool>> isMatch) { var filters = new Expression<Func<T, bool>>[]{ x => x.PriceDefinition.CompanyId == companyId, isMatch }; return GetCount(filters); } public virtual int GetCount( IEnumerable<Expression<Func<T, bool>>> filters) { IQueryable<T> _query = ObjectSet; if (filters != null) { foreach (var filter in filters) { _query = _query.Where(filter); } } return _query.Count(); } When using: count(some_guid, x => x

“The LINQ expression node type 'Invoke' is not supported in LINQ to Entities” - stumped!

左心房为你撑大大i 提交于 2019-12-17 04:27:29
问题 In my EF later, I'm trying to pass in an anonymous function to be used as part of my Linq query. The function would pass in an INT and return a BOOL (u.RelationTypeId is an INT). Below is a simplified version of my function: public IEnumerable<UserBandRelation> GetBandRelationsByUser(Func<int, bool> relation) { using (var ctx = new OpenGroovesEntities()) { Expression<Func<UsersBand, bool>> predicate = (u) => relation(u.RelationTypeId); var relations = ctx.UsersBands.Where(predicate); //

C# - code to order by a property using the property name as a string

戏子无情 提交于 2019-12-17 04:12:53
问题 What's the simplest way to code against a property in C# when I have the property name as a string? For example, I want to allow the user to order some search results by a property of their choice (using LINQ). They will choose the "order by" property in the UI - as a string value of course. Is there a way to use that string directly as a property of the linq query, without having to use conditional logic (if/else, switch) to map the strings to properties. Reflection? Logically, this is what

LEFT JOIN in LINQ to entities?

妖精的绣舞 提交于 2019-12-17 03:53:35
问题 I'm trying out LINQ to entities. I have a problem with the following: I want it to do this: SELECT T_Benutzer.BE_User ,T_Benutzer_Benutzergruppen.BEBG_BE FROM T_Benutzer LEFT JOIN T_Benutzer_Benutzergruppen ON T_Benutzer_Benutzergruppen.BEBG_BE = T_Benutzer.BE_ID the closest thing I've come to is this: var lol = ( from u in Repo.T_Benutzer //where u.BE_ID == 1 from o in Repo.T_Benutzer_Benutzergruppen.DefaultIfEmpty() // on u.BE_ID equals o.BEBG_BE where (u.BE_ID == o.BEBG_BE || o.BEBG_BE ==

LINQ to Entities case sensitive comparison

穿精又带淫゛_ 提交于 2019-12-16 20:14:05
问题 This isn't a case-sensitive comparison in LINQ to Entities: Thingies.First(t => t.Name == "ThingamaBob"); How can I achieve case sensitive comparison with LINQ to Entities? 回答1: That's because you are using LINQ To Entities which is ultimately convert your Lambda expressions into SQL statements. That means the case sensitivity is at the mercy of your SQL Server which by default has SQL_Latin1_General_CP1_CI_AS Collation and that is NOT case sensitive. Using ObjectQuery.ToTraceString to see

specifying the foreign key to the table programmatically by using fluentapi

半城伤御伤魂 提交于 2019-12-14 04:22:29
问题 hi is there any possibility to assign a foriegnkey to table using entity .... pls see this question for clarification.. how do add a single entry for two tables using linq to entities let me explain clearly..... i have a product table product_id product_name product_description category_id category table category_id category_name unfortunately it is not posssible to specify the category_id as a foreign key at the time of creating table the entity table it self taken the category_id as a

Excluding large List<int> from LINQ to Entities query

佐手、 提交于 2019-12-14 04:19:54
问题 I have a List containing a high number of items - up to 10,000. I am looking for the most efficient way to exclude these from an IQueryable/List. Due to the complexity of the process involved in obtaining this list of Ids, it isn't possible to do this within a query. The example below has an extremely high overhead and wondered if anybody might be able to explain possible reasons for this and if there's a better way to achieve this? results = from q1 in results where excludedRecords.All(x =>

Factoring out expressions in linq queries

淺唱寂寞╮ 提交于 2019-12-14 03:57:13
问题 Let's say I have the following Linq2Entities query for some service method: public IQueryable<CustomerProjection>() { return from i in this.DbContext.Customers select new CustomerProjection() { Reference = new EntityReference() { Id = i.Id, Name = i.Name } } } All my model entities, including Customer, all support the following interface: interface INamedEntity { String Name { get; set; } Guid Id { get; set; } } so that in principle I'm tempted to do some refactoring: public IQueryable