Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用.mdf数据库的C窗体应用程序中的Linq到sql问题_C#_Linq_Linq To Sql - Fatal编程技术网

C# 使用.mdf数据库的C窗体应用程序中的Linq到sql问题

C# 使用.mdf数据库的C窗体应用程序中的Linq到sql问题,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我对C表格申请有问题。我正在连接到一个.mdf数据库,并试图查询一个名为SpotLanding的列,该列是bool,然后计算为true的数字。它位于LogbookDatabase.mdf中,位于EnterTable表中。以下是我到目前为止的情况: private void SpotLandingButton_Click(object sender, EventArgs e) { DataContext db = new DataContext(@"C:\Logb

我对C表格申请有问题。我正在连接到一个.mdf数据库,并试图查询一个名为SpotLanding的列,该列是bool,然后计算为true的数字。它位于LogbookDatabase.mdf中,位于EnterTable表中。以下是我到目前为止的情况:

    private void SpotLandingButton_Click(object sender, EventArgs e)
    {

        DataContext db = new DataContext(@"C:\LogbookDatabase.mdf");
        Table<EnterTable> entrytable = db.GetTable<EnterTable>();
        var spot = (from SpotLanding in entrytable
                    where SpotLanding = true
                    select SpotLanding).Count;

        return spot;
    }
这就是它给我的错误

无法将类型“bool”隐式转换为“ParagliderLogBook.EnterTable”

任何人能提供的任何信息都会很好。我尝试了很多不同的方法来完成这项工作,但都出现了相同的错误。

您需要访问对象的SpotLanding成员,顺便说一下,该成员不应也被称为SpotLanding,因为这很容易混淆

此外,您还可以使用以下命令更简洁地编写查询:

您试图分配一个布尔值,而不是比较它

where SpotLanding == true

您需要使用==运算符,而不是=

var spot = (from SpotLanding in entrytable
                where SpotLanding == true
                select SpotLanding).Count;

不知道这是否是唯一的问题,但您正在赋值,而不是比较=true应该是==true更好,entryTable.Countx=>x.SpotLanding。@Jacob:谢谢,是的,您是对的。。。那好多了!更新。
where SpotLanding == true
var spot = (from SpotLanding in entrytable
                where SpotLanding == true
                select SpotLanding).Count;