linq-to-entities

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

穿精又带淫゛_ 提交于 2019-12-24 02:43:04
问题 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,

Using LINQ with IBM i

允我心安 提交于 2019-12-24 00:29:47
问题 Has anyone been able to use LINQ with the IBM i? That is without having to write a custom provider? 回答1: I haven't worked with IBM i directly, but IBM has a page that outlines the limitations of using LINQ to Entities with their product outlined here: http://www.ibm.com/developerworks/wikis/display/DB2/IBM+Data+Server+LINQ+Entity+Framework+Limitations Note that there is no (official) support for any other platform but SQL Server when using LINQ-to-SQL, so you won't be able to use it for

entity framework - how can I implement this SQL in the abbreviated EF linq

☆樱花仙子☆ 提交于 2019-12-24 00:19:08
问题 Can anyone help out with what the C# code would be to implement this SQL as Entity Framework Linq in the abbreviated form? (e.g. where you have the "." notation such as xxx.where(... etc) SELECT PN.Name, Sum(U.Amount) FROM Usages as U, ProcessNames as PN WHERE PN.Id == U.ProcessNameId AND U.Datetime BETWEEN '2010-01-08' AND '2010-10-11' Group By PN.Name 回答1: Method-Based Query: To implement this in lambda we need to leverage Queryable.GroupJoin: var query = context.ProcessNames .GroupJoin

How to get the max timestamp and groupby another field in LINQ to Entities

∥☆過路亽.° 提交于 2019-12-23 23:32:10
问题 I have an Entity with the following fields GUID TaskId, GUID SubTaskId, DateTime Timestamp The TaskId may be one-to-many with the SubTaskId. It's like a composite key almost. I would like to write an expression or expressions resulting in the newest among each TaskId i.e. TaskId SubTaskId Timestamp 1 A 2010-11-22 15:48:49.727 1 B 2010-11-22 16:24:51.117 2 C 2010-11-15 11:49:05.717 2 D 2010-11-15 14:02:11.467 Would result in a sequence containing only: TaskId SubTaskId Timestamp 1 B 2010-11-22

Why does this LINQ expression break my loop & conversion logic?

时间秒杀一切 提交于 2019-12-23 21:31:16
问题 Background ArticleService is a class that provides methods for front-end layers to facilitate business with the back-end. Two of its base responsibilities are to convert ViewModels ( ArticleViewModel ) to the appropriate Models ( Article ) when persisting data, and the reverse, convert Models to ViewModels when fetching data... so often that I created a private method building ViewModel objects: private ArticleViewModel BuildViewModel(Article a) { return new ArticleViewModel { Title = a.Title

LINQ Conditionally Add Join

拈花ヽ惹草 提交于 2019-12-23 21:31:06
问题 I have a LINQ query where I'm trying to return data from 2 tables, but the tables that I join are conditional. This is what I'd like to do: if (teamType == "A"){ var query = from foo in context.People join foo2 in context.PeopleExtendedInfoA select foo; } else { var query = from foo in context.People join foo2 in context.PeopleExtendedInfoB select foo; } Then later on I'm filtering the query down even further. I obviously can't set it up this way because I won't be able to access "query"

The argument types 'Edm.String' and 'Edm.Int32' are incompatible for this operation

百般思念 提交于 2019-12-23 18:24:06
问题 I am getting the error like above tag which will be at the place of return View(st.employees.Find(id)); above place only ,can any one help me from this! and my code is namespace StartApp.Controllers { public class EmployController : Controller { StartEntities st = new StartEntities(); //List public ActionResult List() { return View(st.employees.ToList()); } //Details public ActionResult Details(int id = 0) { return View(st.employees.Find(id)); } //Create public ActionResult Create() { return

LINQ to Entities does not recognize method

孤街醉人 提交于 2019-12-23 18:16:42
问题 I have a long Linq To Entities query:- reports = db.CallProfileDailies .Join(db.ReportDailyTotals, cpd => cpd.Date, rdt => rdt.Date, (cpd, rdt) => new { cpd = cpd, rdt = rdt }) .Where(a => a.cpd.Skill == a.rdt.Skill) .Join(db.SummaryIntervalTotals, a => a.rdt.Date, sit => sit.Date, (a, sit) => new { cpd = a.cpd, rdt = a.rdt, sit = sit }) .Where(a => a.rdt.Skill == a.sit.Skill) .Select((a, i) => new ReportModel { AverageAbandonDelay = a.sit.AvgAbanTime, AverageAfterCallWorkTime = a.sit

Why does EF add tons of unused OUTER APPLY clauses when I put OrderBy at the beginning of my query

冷暖自知 提交于 2019-12-23 18:03:48
问题 tl;dr; Putting orderby contact.Property before my projection ( let defaultAddress = contact.Addresses... ) creates an exponentially more complex SQL statement and sometimes causes an OutOfMemoryException. Question I have a simple data model for storing contact information public class Contact { public int ContactID { get; set; } public virtual ICollection<Address> Addresses { get; set; } //etc } public class Address { public int AddressID { get; set; } public int ContactID { get; set; }

In Linq to Entities can you convert an IQueryable into a string of SQL?

雨燕双飞 提交于 2019-12-23 18:01:28
问题 eg. var result = myObject.Where(x => x.prop == 5); string s = result.toSQL(); Result: s is "SELECT * FROM [myObjects] WHERE prop = 5" 回答1: If it's IQueryable / ObjectQuery you can use ToTraceString. If it's IDbSet/DbSet you can use ToString directly. 回答2: Using EF 6 I could not get .ToString() to return SQL for something similar to: db.Entry(parent) .Collection(p => p.Children) .Query() .Where(c => c.Active) .Load(); Then I remembered you can log it to debug output with: db.Database.Log =