linq-to-entities

.Include() .Where() .Select() in Linq to Entities Query

╄→гoц情女王★ 提交于 2020-01-14 11:51:22
问题 I have a Linq query that queries the following tables: Tasks with a one-to-many link to: TaskLinks and TaskLinks has a one-to-one link to a Table called Entities. I am trying to select the task, eager load (via .Include) the TaskLinks and select the Entity linked to the TaskLink. But I need to filter the Task (by Access Level int) and the TaskLinks so that I don't include any Inactive (bool) records. Here is my Linq query: Tasks.Where(t => t.AccessLevel <= 5) .Include(tl => tl.TaskLinks.Where

Is it possible to call named method within a call to Where?

让人想犯罪 __ 提交于 2020-01-14 09:11:30
问题 I am trying to understand some performance implication of Linq from this free ebook by RedGate ftp://support.red-gate.com/ebooks/under-the-hood-of-net-memory-management-part1.pdf On page 157-158 in this book, they created following example. Order[] pastDueAccounts = null; DateTimedueDate = DateTime.Today.AddDays(-7); using(varcontext = new Context()) { pastDueAccounts = context.Accounts.Where(account => account.DueDate < dueDate).ToArray(); } They then re-factored part of lamda expression

How do I perform date-part comparison in EF

霸气de小男生 提交于 2020-01-14 08:43:09
问题 i heard people saying date time comparison do not work just due to time part because datetime has time part. in sql i always compare datetime like this way and it works fine select * from employee where convert(varchar,dob,112) > '20111201' // this yyyymmdd format. how could i simulate this in a LINQ query? 回答1: The one thing to keep in mind is that operations on DateTime structs that represent database columns don't translate to SQL. So, you cannot write a query like: from e in

linq to entities orderby strange issue

一世执手 提交于 2020-01-14 05:30:12
问题 maybe foolish question, first times with linq to entities (well, linq in general). table with id(int), value(decimal), name(string) for each record i need id list<string> id value name THE FOLLOWING WORKS FINE int pageSize=10 int pageIndex=2 var data = (from c in db.Customers orderby c.ID select new { c.ID, c.Value, c.Name } ).Skip(pageSize * pageIndex).Take(pageSize).ToArray(); but doesn'organize the data in the way i need them. However the results are like: 1 100 name A 2 300 name B 3 200

linq to entity: linq query performance optimization

喜你入骨 提交于 2020-01-13 13:53:12
问题 i'm using EF 4.4.20627.0 with MySQL 5.6 , MySQL .net connector version 6.6.4 i have a method like this, which generated sql is very very slow (needs more than 1 min) private List<TNews> GetPagedNews(int pagenum, int pagesize, AdvSearcherArgs advcArgs, string keyword) { var dataSrc = _dbRawDataContext.TNews.Where(x => x.Id>0); if (!string.IsNullOrWhiteSpace(advcArgs.PMAC)) { dataSrc = dataSrc.Where(m => m.Pmac == advcArgs.PMAC); } if (!string.IsNullOrWhiteSpace(advcArgs.BegineDate)) { var

linq to entity: linq query performance optimization

旧街凉风 提交于 2020-01-13 13:52:54
问题 i'm using EF 4.4.20627.0 with MySQL 5.6 , MySQL .net connector version 6.6.4 i have a method like this, which generated sql is very very slow (needs more than 1 min) private List<TNews> GetPagedNews(int pagenum, int pagesize, AdvSearcherArgs advcArgs, string keyword) { var dataSrc = _dbRawDataContext.TNews.Where(x => x.Id>0); if (!string.IsNullOrWhiteSpace(advcArgs.PMAC)) { dataSrc = dataSrc.Where(m => m.Pmac == advcArgs.PMAC); } if (!string.IsNullOrWhiteSpace(advcArgs.BegineDate)) { var

Prevent NULL checks in LINQ to Entity Joins

不打扰是莪最后的温柔 提交于 2020-01-13 11:33:40
问题 We have a table called Student . That table has a field called Homeroom , where the value is a room number of the student's homeroom. The value can be null. We have a second table called Staff . That table also has a field called Homeroom to indicate which homeroom the teacher is assigned to. The value can be null. But when the student's Homeroom is null, a Staff record should not be returned. We used to take advantage of the fact that checking two null fields for equality always returns

Prevent NULL checks in LINQ to Entity Joins

北城余情 提交于 2020-01-13 11:33:06
问题 We have a table called Student . That table has a field called Homeroom , where the value is a room number of the student's homeroom. The value can be null. We have a second table called Staff . That table also has a field called Homeroom to indicate which homeroom the teacher is assigned to. The value can be null. But when the student's Homeroom is null, a Staff record should not be returned. We used to take advantage of the fact that checking two null fields for equality always returns

Is there a DataContext in LINQ-to-Entities (NOT Linq-to-SQL)?

大城市里の小女人 提交于 2020-01-13 08:57:07
问题 I recently asked a question about tracing Linq-to-Entities I think that one of the answers was not right, as they refer to using the DataContext. Is there a DataContext for LINQ-to-Entities? If so, how do I get it? 回答1: LINQ to Entities uses ObjectContext, not DataContext. Here is a short description of EF: LINQ to Entities, the ObjectContext Class, and the Entity Data Model LINQ to Entities queries use the Object Services infrastructure . The ObjectContext class is the primary class for

Include and Where predicate cause left join instead of inner join

吃可爱长大的小学妹 提交于 2020-01-13 08:43:13
问题 With the following table structure (extraneous columns removed) create table [Events] ( ID int not null identity, Name nvarchar(128) not null, constraint PK_Events primary key(ID) ) create table [Donations] ( ID int not null identity, EventID int not null, Amount decimal(10, 2) not null, constraint PK_Donations primary key(ID), constraint FK_Donations_Events foreign key(EventID) references [Events](ID) on update no action on delete no action ) I use the following Linq-to-Entities queries: //