c# - linq2db.MySql - 无法找到源类型的查询模式的实现。未找到的地方

标签 c# mysql linq

Visual Studio 2017 C# 我正在尝试为 MySQL 实现 Linq2db,作为 Linq 新手,我遇到了一些麻烦。我试图遵循 GitHub linq2db 中的示例,使用一个简单的两列表(邮件列表)——整数列表和 client_id,它们一起是主键。 我已经从 nuget 安装了 linq2db.MySql ,包括 linq2db 和 linq2db.t4models。使用“传统”方法,我可以处理数据库,以便连接正常工作。这就是我到目前为止所做的。

我的应用程序配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
    </startup>
    <connectionStrings>
                <add name="MyWinBroker" connectionString="Server=localhost;Port=3306;Database=winbroker;Uid=root;Pwd=DeValk@123!;charset=utf8;" providerName="MySql.Data.MySqlClient"/>
            </connectionStrings>
</configuration>

POCO 类:

using LinqToDB.Mapping;
using LinqToDB;

[Table(Name = "maillist")]
public class Mailing
{
    [PrimaryKey, Identity]
    public int List { get; set; }
    public int Client_id { get; set; }

    [Column(Name = "list"), NotNull]
    public int MailList { get; set; }
    [Column(Name = "client_id"), NotNull]
    public int Client { get; set; }
}
public class DbWinbroker : LinqToDB.Data.DataConnection
{
    public DbWinbroker() : base("MyWinbroker") { }
    public ITable<Mailing> Mailing { get { return GetTable<Mailing>(); } }

}

查询

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.FileIO;
using FileHelpers;
using FileHelpers.Events;
using Itenso.TimePeriod;
using MySql.Data.MySqlClient;
using LinqToDB;
using System.Collections.Generic;

public static List<Mailing> All()
{
    using (var db = new DbWinbroker())
    {
        var query = from p in db.Mailing  
                    where p.MailList < 99
                    select p;
        return query.ToList();
     }
}

这不会编译我在查询中的 db.Mailing 下看到红色波浪线和错误:

Could not find an implementation of the query pattern for source type 'ITable<Form1.Mailing>'. 'Where' not found. 

如果我删除 where 子句,则会收到两个不同的错误。 也许我确实需要包含引用文献,但是哪个?

The type of the expression in the select clause is incorrect.  Type inference failed in the call to 'Select'.
'T' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)

我看过很多关于此错误变体的帖子,但我仍然不明白。 任何帮助将不胜感激。

TIA, 格里。

最佳答案

哎呀!我忘记使用 system.Linq;

如果给大家带来任何麻烦,我深表歉意。

关于c# - linq2db.MySql - 无法找到源类型的查询模式的实现。未找到的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922454/

相关文章:

c# - WCF - 绑定(bind)错误

使用 CURRENT_DATE 减去数值时 MySQL 的奇怪行为

MySQL 查询 GROUP, COUNT

c# - 创建存储库

vb.net - LINQ分组依据问题

c# - SQL Server 关闭时,SqlConnection OpenAsync 会阻止 UI

c# - 如果不调用 Dispose,IDbCommand、IDataReader 或 DataTable 会泄漏资源吗?

mysql - 使用 LEFT JOIN 对相同的行进行分类,而无需重复一对多关系

c# - 如何比较两个列表并将值设置为列表属性

c# - 处理空结果