简体   繁体   English

复杂的LINQ to SQL查询

[英]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. 我有以下LINQ to SQL查询,我想根据数据库中的bool值传递特定的字符串。

                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). 而不是"male/female"字符串我想通过其中malefemale取决于在用户数据库中的d.usrSex布尔值的字符串(如usrSex == true,那么我通过“男性”的字符串)。 How can I put if condition in there to check the bool value? if条件存在,如何检查布尔值?

使用三元运算符

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM