Click here to Skip to main content
15,891,645 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am currently struggling with the getting the bool type "sdata_ALL" parameter, in a linq where condition. the "data_ALL" field can have values 0 or 1. I am using the sql query below to convert it into linq query, but I having difficulty with the bool type parameter.

C#
public bool subs(string username, string password)
       {
           //define the query : query will be an IQueryable
           var query = from s in db.Subscriptions
                       join u in db.UserDetails on s.sUID equals u.uID
                       where s.BS_ExpiryDate >= DateTime.Now &&
                       s.sPID.Value == 163 &&
                       s.data_All.Value ==  1 &&
                       u.uUsername == username &&
                       u.uPassword == password
                       select u; //

           // "execute" the query
           return query.FirstOrDefault() != null; // if there is a result it will return true
       }

Any insight to what I may be missing or doing wrong?
Many thanks.
Posted
Updated 22-Dec-16 16:06pm
v2

OKay,
FirstOrDefault() returns the first element of a sequence, or a default value if the sequence contains no elements.

So if I'm not mistaken then you're getting string or maybe a char value, and the method is return bool value. Instead, what you can do is change the return type of your method.

-KR
 
Share this answer
 
We can get result by applying true instead of 1 in the Boolean type parameter

Example:

(from id in objeApp_SchemaEntities.AspNetUsers where id.IsAdmissionAccount == true select id.Id).FirstOrDefault();
 
Share this answer
 
I manage to figure out that for the boolean type, it should be true/false return.

C#
var query = from s in db.Subscriptions
                        join u in db.UserDetails on s.sUID equals u.uID
                        where s.BS_ExpiryDate >= DateTime.Now &&
                        s.sPID.Value == 163 &&
                        s.data_All.Value ==  true &&
                        u.uUsername == username &&
                        u.uPassword == password
                        select u; //
 
Share this answer
 

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