我有一些困难,为我的LINQ查询中包含的项目添加一些过滤条件。我的查询就像实体框架包含过滤器子集合
var item = _Context.Order.Include("Inner")
.Include("Inner.first")
.Include("Inner.second")
.Where(x => (!(x.IsDeleted) && (x.IsActive) &&
(x.itemid == id))).FirstOrDefault();
在上面的代码中“Inner”是另一个项目列表。现在我需要过滤内部物品。我只需要过滤条件inner.isDeleted = true的内部项目。
查询应返回一类像,
public class Order
{
public string Name { get; set; }
public List<InnerDetails> Inner{ get; set; }
public bool IsDeleted { get; set; }
}
和InnerDetails类像
任何人都可以建议我一个更好的方法来做到这一点,因为我在LINQ和EF
究竟是你想过滤 - 你想,只包括order.inner.isdeleted的从order.inner条目,或者你要删除的整个记录例如不符合条件的整行订单?如果是第二个,那么如果你有两个条目order.inner,其中isDeleted = true,其中isDeleted = false – Alex
@Alex:我在问题中提到'我只需要内部过滤条件的内部项目。 isDeleted = true。',即我只需要包含删除的内部记录(inner.isDeleted = true)。这只是内部记录,这不会影响外部记录。 –
看来你正试图过滤嵌套列表。我认为这个问题可能会帮助你http://stackoverflow.com/questions/25183685/how-to-filter-nested-list-using-linq-lambda和这一个http://stackoverflow.com/questions/7079378/how -to-filter-nested-collection-entity-framework-objects – Alex