Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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# Dapper:具有重复列名的多重映射_C#_Dapper - Fatal编程技术网

C# Dapper:具有重复列名的多重映射

C# Dapper:具有重复列名的多重映射,c#,dapper,C#,Dapper,我有一张这样的桌子: ID ERR1 ERR2 ERR3 ---- ---- ---- ---- 05A2 A001 B223 C212 06B3 B392 C234 D234 ... public class Entry { public string Id { get; set; } public List<BpcError> Errors { get; set; } public Entry() { Errors = ne

我有一张这样的桌子:

ID   ERR1 ERR2 ERR3
---- ---- ---- ----
05A2 A001 B223 C212
06B3 B392 C234 D234
...
public class Entry
{
    public string Id { get; set; }
    public List<BpcError> Errors { get; set; }

    public Entry()
    {
        Errors = new List<BpcError>();
    }
}

public class BpcError
{
    public string ErrorCode { get; set; }
    // More properties and methods to follow
}
我想将其映射到如下所示的对象:

ID   ERR1 ERR2 ERR3
---- ---- ---- ----
05A2 A001 B223 C212
06B3 B392 C234 D234
...
public class Entry
{
    public string Id { get; set; }
    public List<BpcError> Errors { get; set; }

    public Entry()
    {
        Errors = new List<BpcError>();
    }
}

public class BpcError
{
    public string ErrorCode { get; set; }
    // More properties and methods to follow
}
公共类条目
{
公共字符串Id{get;set;}
公共列表错误{get;set;}
公众进入()
{
错误=新列表();
}
}
公共类BPCEROR
{
公共字符串错误代码{get;set;}
//要遵循的更多属性和方法
}
我怎样才能做到这一点?

以下是方法:

string sql = "SELECT ID, "
    + "ERR1 AS ErrorCode, "
    + "ERR2 AS ErrorCode, "
    + "ERR3 AS ErrorCode "
    + "FROM ERR_TB";

List<Entry> entries = connection.Query<Entry, BpcError, BpcError, BpcError, Entry>(sql,
(entry, e1, e2, e3) =>
{
    if (e1 != null)
        entry.Errors.Add(e1);

    if (e2 != null)
        entry.Errors.Add(e2);

    if (e3 != null)
        entry.Errors.Add(e3);

    return entry;
},
splitOn: "ErrorCode, ErrorCode, ErrorCode")
.ToList();
string sql=“选择ID,”
+错误1作为错误代码
+ERR2作为错误代码
+“ERR3作为错误代码”
+“来自ERR_TB”;
列表条目=connection.Query(sql,
(条目e1、e2、e3)=>
{
如果(e1!=null)
entry.Errors.Add(e1);
如果(e2!=null)
entry.Errors.Add(e2);
如果(e3!=null)
entry.Errors.Add(e3);
返回条目;
},
splitOn:“错误代码,错误代码,错误代码”)
.ToList();