这是我的代码:
Dim QSD = From VM In cntxtVessel.VesselMasters _
Group Join cnt In cntxtVessel.CountryMasters On VM.CountryCode Equals cnt.CountryCode Into Cntry = Group _
From CM In Cntry.DefaultIfEmpty _
Group Join D In cntxtVessel.DestinationMasters On VM.DestinationCode Equals D.DestinationCode Into Dest = Group _
From DM In Dest.DefaultIfEmpty _
Group Join Car In cntxtVessel.CarrierMasters On VM.ClientCode Equals Car.CarrierCode Into Cr = Group _
From CS In Cr.DefaultIfEmpty _
Where VM.VesselCode <> 0 _
Order By VM.VesselName Ascending _
Select VesselCode = VM.VesselCode, VesselID = VM.VesselID, VesselName = VM.VesselName, ServiceType = VM.ServiceType, ClientCode = CType(CS.CarrierCode, Int32), Agent = CS.CompanyName, RefNo = VM.RefNo, VesselType = VM.VesselType, Length = VM.Lenght, Width = VM.Weight, Height = VM.Height, VesselBuiltDate = VM.VesselBuiltDate, AgeOfShip = VM.AgeOfShip, ShipBuilder = VM.ShipBuilder, CountryCode = CType(CM.CountryCode, Int32?), CountryName = CType(CM.CountryName, String), DestinationCode = CType(VM.DestinationCode, Int32?), DestinationName = DM.DestinationName, Flag = VM.Flag, CallSign = VM.CallSign, IMONo = VM.IMONo, NRT = VM.NRT, ContactPerson = VM.ContactPerson, MobileNo = VM.MobileNo, TPNo = VM.TPNo, Fax = VM.Fax, Email = VM.Email, Web = VM.Web, Remarks = VM.Remarks, InActive = VM.InActive
ugrdVessel.DataSource = QSD
上面的(左外连接)代码在某些列中返回空值(例如Country Code=Null, DestinationCode=null,Agent=Null
)我如何预先保存此空返回值
答案 0 :(得分:0)
如下所示,您可以获得非空值的客户
var query = from cust in Context.Customers
where cust.CustomerName != null
group cust by c.CustomerName into groupby
select new { groupby.Key, Count = groupby.Count() };
VB.Net
Dim query = From groupby In From cust In Context.Customers Where cust.CustomerName IsNot NothingGroup cust By c.CustomerNameNew With { _
groupby.Key, _
Key .Count = groupby.Count() _
}
修改 - 用于处理空值
The C# ?? null coalescing operator (and using it with LINQ)