linq-to-entities

Using custom methods in linq to entities

自作多情 提交于 2019-12-24 05:19:27
问题 I have a Person table in my database that has NationalId field. Is there any way to load all Persons with even NationalId , using Ef code first and Linq to entities , without loading all Person s to memory? Somethings like: public bool IsEven(int number) { return number % 2 == 0; } var context = new MyContext(); var personsWithEvenNationalId = context.Persons .Where(x=> IsEven(x.NationalId)) .ToList(); 回答1: You would have to do your check inline var personsWithEvenNationalId = context.Persons

how can i get the membership sold count

南笙酒味 提交于 2019-12-24 04:19:33
问题 Hi I have a table called membertomship with columns... memberToMship_Id memberToMship_StartDate memberToMship_EndDate memberToMship_JoinFee memberToMship_ChargePerPeriod memberToMship_InductionFee mshipOption_Id and i have another table called mshipoptions with columns mshipOption_Id mshipOption_Period mshipType_Id and i have another table mshiptypes mshipType_Id mshipType_Name and my datacontext name is tsgdbcontext how can i convert below query into linq "SELECT mshipType_Name, COUNT('A')

Error “The LINQ expression node type 'Invoke' is not supported in LINQ to Entities” in where clause inside the method

淺唱寂寞╮ 提交于 2019-12-24 03:37:15
问题 When I execute my query: rs.Select(x => x.id).ToArray(); I obtain this error: The LINQ expression node type 'Invoke' is not supported in LINQ to Entities This is the method that generates the error (probably func(x) ): public IQueryable<TEntity> Compare<TEntity>(IQueryable<TEntity> source, Func<TEntity, int> func) { IQueryable<TEntity> res = source; if (!this.LBoundIsNull) res = res.Where(x => func(x) >= _lBound); if (!this.UBoundIsNull) res = res.Where(x => func(x) <= _uBound); return res; }

Convert TSQL to Linq to Entities

假如想象 提交于 2019-12-24 03:34:54
问题 I have 2 table named FileList and ExtensionsCategory : FileList ------------------------------------------------------------- ID Path Extension 1 C:\7.pdf pdf 2 D:\3.png png 3 C:\1.mp3 mp3 4 D:\32.pdf pdf and ExtensionsCategory ------------------------------------------------------------ ID Extension Category 1 mp3 Multimedia 2 pdf Document 3 png Photo there isn't any relation between tables. now i want to know each category contain how many files ? i wrote the following TSQL query in SSMS

E2L: How do you handle Foreign Keys that participate in multiple relationships?

↘锁芯ラ 提交于 2019-12-24 03:33:13
问题 I have a Database model like this FlowObject FlowObjectID (PK) Description Active ProcessObject FlowObjectID (PK, FK) HasSubmit DecisionObject FlowObjectID (PK, FK) YesFlowObjectID (FK) NoFlowObjectID (FK) YesCaption NoCaption When I try and use create my Entity model I get this warning in my project. Foreign Key constraint 'FK_ProcessObject_FlowObject1' has been omitted from the storage model. Column 'FlowObjectID' of table 'Investigations.Store.ProcessObject' is a Foreign Key participating

Not Able to Select MySQL from Choose Data Source In Visual Studio 2013

你说的曾经没有我的故事 提交于 2019-12-24 03:29:05
问题 I am trying to use Linq-to-Entity and connect with my local mysql database. But, when i select the mySql at the Choose Data Source Part. I hit the error as below: An error occurred that is normally caused by not having for Visual Studio properly installed. But I did install > Uninstall > re-install Visual Studio 20143 again. The error still come out. I also have try to Install like the below: https://stackoverflow.com/a/20589057/1034986 also not work. Can anyone help me? Thanks a lot. 来源:

Reusable functions for use with Linq-to-Entities

荒凉一梦 提交于 2019-12-24 03:21:35
问题 I have some stats code that I want to use in various places to calculate success / failure percentages of schedule Results . I recently found a bug in the code and this was due to the fact it was replicated in each LINQ statement, I then decided it would be better to have common code to do this. The problem being, of course, is that a normal function, when executed on SQL server, throws a NotSupportedException because the fuinction doesnt exist in SQL Server. How can I write a reusable stats

Linq to Entities simple group query

末鹿安然 提交于 2019-12-24 02:54:09
问题 How to write (simple) LINQ to Entities query that groups elements by some attribut and count them? SELECT answernumber, count(answerID) FROM answers WHERE questionID = id GROUB BY answernumber ORDERBY answernumber; That should be simple but i don't know how to write it. 回答1: var query = answers .GroupBy(a => a.answernumber, a => a, (k, g) => new {answernumber = k, Count = g.Count()}) .OrderyBy(i => i.answernumber); Or the other way: var query2 = from a in answers group a by a. answernumber

LINQ to Entities does not recognize the method 'Int64 Max(Int64, Int64)' method, and this method cannot be translated into a store expression

故事扮演 提交于 2019-12-24 02:47:49
问题 I'm getting this error message during runtime LINQ to Entities does not recognize the method 'Int64 Max(Int64, Int64)' method, and this method cannot be translated into a store expression. when I try to do this: return _dbContext.Appointment.Where(x => Math.Max(x.Appointment.StartTime.Ticks, startTime.Ticks) <= Math.Min(x.Appointment.EndTime.Ticks, endTime.Ticks)); The idea behind this query is that "if the latest start time is before the earliest end time, then you have some overlap/touching

Why 'Lambda' is not supported in my LINQ to Entities syntax [duplicate]

↘锁芯ラ 提交于 2019-12-24 02:43:05
问题 This question already has answers here : “The LINQ expression node type 'Invoke' is not supported in LINQ to Entities” - stumped! (4 answers) Closed 6 years ago . I get an error when I try to run the following query in LINQ to Entities: public IEnumerable TestOne2() { var query = this.Context.CmnAddressCities .Join(this.Context.CmnAddressStates, p => p.StateID, q => q.StateID, (p, q) => SelectSearchColumns) .ToList(); return query; } public Expression<Func<CmnAddressCity,CmnAddressState,