简体   繁体   English

在 linq-to-sql 中返回 bool true

[英]returning bool true in linq-to-sql

I have an object model that contains a boolean field MyBool.我有一个 object model 包含一个 boolean 字段 MyBool。 I want populate that boolean with a linq-to-sql query based on whether or not the database field MyField contains data.我想根据数据库字段 MyField 是否包含数据,用 linq-to-sql 查询填充 boolean。

This is what I have:这就是我所拥有的:

var TheQuery = (from x in .....
                where .....
                select new MyModel{

                    MyBool = x.MyField.Contains(*)

                }).ToList();

I'm trying with the.Contain extension method but it's not working.我正在尝试使用 .Contain 扩展方法,但它不起作用。 Any suggestions?有什么建议么?

Thanks谢谢

I'd suggest that, according to your incomplete example,我建议,根据你不完整的例子,

MyBool = x.MyField.Contains(*)

should be应该

MyBool = x.MyField.Contains("*")

And you should have brackets around the Linq expression.你应该在 Linq 表达式周围有括号。

A more complete example might be useful, though.不过,一个更完整的示例可能会很有用。

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

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