tags:

views:

20

answers:

1

Hi, There,

here's My Code:

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

the above (left outer Join) code return the null value in some column (ex. Country Code=Null, DestinationCode=null,Agent=Null) how do i prenevt this null return values

A: 

Do some thing as below where you get customer with not null value

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() _
}

Edit - for handling null value

The C# ?? null coalescing operator (and using it with LINQ)

alt text

Pranay Rana
thanks vb.net please
Suhaibnm
@Suhaibnm - ans updated ...........
Pranay Rana
There is no grouping only left Outer Join If Null return I want make that in to 0 / '' I mean we usually doing in sql query Ex: isnull(fieldname,0) / isnull(fieldname,'')
Suhaibnm
@Suhaibnm - check scott gu article to handle nulls in linq with ?? operator
Pranay Rana
thanks for help me rana
Suhaibnm
@Suhaibnm - you will get better answer if you start incresing you acceptance rate by accepting answer
Pranay Rana