如何使用LINQ获得NOT Equal功能?

时间:2014-10-31 08:01:00

标签: c# linq

我想从 HireGroupDetails 中获取车辆的所有记录,但不知道如何获得 NOT EQUAL 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 个答案:

答案 0 :(得分:0)

我认为这就是你所需要的:

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,
                     };