Search code examples
c#sqllinqwindows-phone-8longlistselector

Complex LINQ to SQL query


I have the following LINQ to SQL query where I want to pass a specific string based on the bool value in the database.

                stuffList = data.Users.AsEnumerable()
                    .Where(x => result.Contains(x.usrName))
                    .Select(d => new mTeachers(d.usrName, d.usrAge, "male/female"))
                    .ToList();

Instead of "male/female" string I want to pass either male or female string depending on the d.usrSex bool value in the Users database (if usrSex == true then I pass "male" string). How can I put if condition in there to check the bool value?


Solution

  • Use the ternary operator

    new mTeachers(d.usrName, (int)d.usrAge, d.usrSex ? "male" : "female")