【问题标题】:.Net MVC Linq query.Net MVC Linq 查询
【发布时间】:2018-05-11 19:16:30
【问题描述】:

在我的程序中,我有一个数据库,其中包含一个包含人员的表。

每个人都有一套衣服,里面有一套面料。假设我想返回衣服含棉的人数。

即使这个人有不止一件含棉的衣服,我也只想数一次。

我尝试了以下和其他几种解决方案,但对我来说效果不佳:

if ((from p in context.Persons
    from c in p.Clothes
    from f in c.Fabrics
    select f.Name == "Cotton").Count();
{ 

【问题讨论】:

    标签: entity-framework linq


    【解决方案1】:
    var count = database.People
        .Where(p => p.Clothes.Any(c => c.Fabrics.Any(f => f.Name == "Cotton")))
        .Count();
    

    选择所有衣服面料是棉的人。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多