c#如何不使用 LINQ 的同等功能吗?

标签: Linq C#
发布时间: 2017/2/28 23:20:01
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我想要所有这些记录从车辆HireGroupDetails有没有匹配,但不知道如何在LINQ中获取不等于功能 !

var fleetHireGroupDetailQuery = from vehicle in db.Vehicles                
                                join hgd in db.HireGroupDetails on
                    new { vehicle.VehicleMakeId, vehicle.ModelYear }
                    equals new {  hgd.VehicleMakeId,  hgd.ModelYear}
                    select new RptFleetHireGroupDetail
                     {
                          PlateNumber = vehicle.PlateNumber,
                     };

解决方法 1:

这是你的需要︰

var fleetHireGroupDetailQuery = from vehicle in db.Vehicles
                                where !(from hgd in db.HireGroupDetails
                                select new {  hgd.VehicleMakeId,  hgd.ModelYear}).Contains(new { vehicle.VehicleMakeId, vehicle.ModelYear })
                    select new RptFleetHireGroupDetail
                     {
                          PlateNumber = vehicle.PlateNumber,
                     };
赞助商