【问题标题】:dapper .net mapping with duplicate model properties for splitOn具有用于 splitOn 的重复模型属性的 dapper .net 映射
【发布时间】:2015-04-13 01:51:36
【问题描述】:

我有两个具有相同属性名称的模型

Class Office<br>
{
   int Id;
   string Name;
   Location Location;
}

Class Location
{
   int Id;
   string Name;
}

sqlConnection.Query<Office, Location, Office>("query", (o, l) => {o.Location=l}, splitOn="Id,Id").ToList();

我怎样才能让它工作。

任何帮助表示赞赏。

【问题讨论】:

    标签: .net mapping duplicates dapper


    【解决方案1】:

    好吧,您只是忘记在委托中返回您的新对象

    (o, l) => {o.Location=l; return o;}
    

    即你应该写:

    sqlConnection.Query<Office, Location, Office>("query", (o, l) => {o.Location=l; return o;}, splitOn="Id,Id").ToList();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多