如何将Sql转换为具有Distinct(id)的Linq
从MT_车辆中选择countdistinct License Plate,其中IsDeleted=0,CreatedBy=1如何将Sql转换为具有Distinct(id)的Linq,sql,linq,linq-to-sql,distinct,Sql,Linq,Linq To Sql,Distinct,从MT_车辆中选择countdistinct License Plate,其中IsDeleted=0,CreatedBy=1 var count = db.MT_Vehicle .Where( v => v.IsDeleted == 0 && v.CreatedBy == 1 ) .Select(v => v.LicencePlate) .Distinct() .Count(); 所以你会期望什么呢?我想根据车牌显示没有重复的车辆总数
var count = db.MT_Vehicle
.Where( v => v.IsDeleted == 0 && v.CreatedBy == 1 )
.Select(v => v.LicencePlate)
.Distinct()
.Count();
所以你会期望什么呢?我想根据车牌显示没有重复的车辆总数,不显示删除的车辆。你知道我没有魔力,对吗?据我所知,你的桌子可能是空的。因此,根据您的描述,您应该删除在CreatedBy上过滤的零件。
var count = MT_Vehicle.Where(x => x.IsDeleted==0 && x.CreatedBy == 1)
.Select(x => x.LicencePlate)
.Distinct()
.Count();