Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using (var db = new AppsDb())
{
    //get the corresponding name in Division. 
    division = (from obs in db.BibleMaster.AsNoTracking()
                select new CommonCustomLookUp { DisplayText = obs.Division}).ToList();
}


What I have tried:

How to check the value is null
Posted
Updated 16-Jan-17 0:27am
v2
Comments
F-ES Sitecore 16-Jan-17 4:38am    
Which value?
Member 12766235 16-Jan-17 4:41am    
division value
F-ES Sitecore 16-Jan-17 4:48am    
if (division == null || division.Count == 0)
Richard Deeming 16-Jan-17 10:59am    
You have two things called Division in your code sample.

As far as I'm aware, it's not possible for the result of the query expression to be null. If there are no matching records, the result will be an empty sequence.

Do you want to exclude records where obs.Division is null?

Try this:
using (var db = new AppsDb())
{
    //get the corresponding name in Division. 
    var data = from obs in db.BibleMaster.AsNoTracking()
                select new CommonCustomLookUp { DisplayText = obs.Division};
               
    if(data!=null)
       division = data.ToList();
}
 
Share this answer
 
Comments
Richard Deeming 16-Jan-17 10:56am    
I don't think it's possible for the result of a query expression to be null. If there are no matching records, the result will be an empty sequence.
using (var db = new AppsDb())
{
    //get the corresponding name in Division. 
    var data = from obs in db.BibleMaster.AsNoTracking()
                select new CommonCustomLookUp { DisplayText = obs.Division};

    //Considering Division is of type String.           
    if(!String.IsNullOrEmpty(data))
       division = data.ToList();
}
 
Share this answer
 
Comments
Richard Deeming 16-Jan-17 10:55am    
Wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900