Linq to Entities多个where子句 [英] Linq to Entities multiple where clause
本文介绍了Linq to Entities多个where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有Person 和PersonName对象的简单EF模型。它们由Person到PersonName之间的一对多关联加入。 PersonName 对象包含一个StartDate和 EndDate。我正在尝试将linq写入实体
查询以过滤掉Person.Id和PersonName.StartDate / PersonName.EndDate。我正在努力做到这一点!
I have a simple EF model with Person and PersonName objects. They are joined by a one to many association from Person to PersonName. The PersonName object contains a StartDate and EndDate. I am trying to write a linq to entities query to filter out by Person.Id and PersonName.StartDate/PersonName.EndDate. I am struggling to do this!
var query = from per in _context.People
where per.Id == id
select query;
推荐答案
检查一下,
public class Person
{
public int Id { get; set; }
public IList<PersonName> PersonNames = new List<PersonName>();
}
public class PersonName
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
List<Person> personList = new List<Person>();
int id = 0;
var persons = from p in personList
where p.Id == id && p.PersonNames.Any<PersonName>(pN => { return pN.StartDate >= DateTime.Now.AddDays(-10); })
select p;
这篇关于Linq to Entities多个where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文