如何使用Distinct(id)将Sql转换为Linq

时间:2018-11-01 09:21:59

标签: sql linq linq-to-sql distinct

从MT_Vehicle中选择IsDeleted = 0且CreatedBy = 1

的计数(不同的LicencePlate)

2 个答案:

答案 0 :(得分:0)

您可以这样写:

var count = db.MT_Vehicle
    .Where( v => v.IsDeleted == 0 && v.CreatedBy == 1 )
    .Select(v => v.LicencePlate)
    .Distinct()
    .Count();

答案 1 :(得分:0)

var count = MT_Vehicle.Where(x => x.IsDeleted==0 && x.CreatedBy == 1)
                      .Select(x => x.LicencePlate)
                      .Distinct()
                      .Count();
相关问题