我有以下 POCO:
public Ticket
{
public int Id { get; set; }
public int IdOwner { get; set; }
public int IdDependency { get; set; }
public string SerialNumber { get; set; }
public Owner Owner { get; set; }
public Dependency Dependency { get; set; }
}
public Owner
{
public int Id { get; set; }
public string Name { get; set; }
// Other attributes
}
public Dependency
{
public int Id { get; set; }
public string Name { get; set; }
// Other attributes
}
我想退回一张List
只有Owner Name
和的门票Dependency Name
。问题是,我会写一个where
ifOwner
在我的过滤器中我通过OwnerId
, 和相同的Dependency
. 查看我的过滤器:
public List<Ticket> SelectTickets(string SerialNumber, int IdOwner, int IdDependency)
{
IQueryble<Ticket> query = context.Tickets.Where(t => t.SerialNumber == SerialNumber);
if (IdOwner != 0)
{
query = query.Where( ?? );
}
if (IdDependency!= 0)
{
query = query.Where( ?? );
}
return query.ToList();
}