我在使用dapper的MultiMaps时遇到了问题,尝试对包含NULL
的列进行拆分。Dapper似乎没有实例化对象,我的映射函数收到的是null
而不是对象。
这是我的新测试:
class Product
{
public int Id { get; set; }
public string Name { get; set; }
public Category Category { get; set; }
}
class Category
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
public void TestMultiMapWithSplitWithNullValue()
{
var sql = @"select 1 as id, 'abc' as name, NULL as description, 'def' as name";
var product = connection.Query<Product, Category, Product>(sql, (prod, cat) =>
{
prod.Category = cat;
return prod;
}, splitOn: "description").First();
// assertions
product.Id.IsEqualTo(1);
product.Name.IsEqualTo("abc");
product.Category.IsNotNull();
product.Category.Id.IsEqualTo(0);
product.Category.Name.IsEqualTo("def");
product.Category.Description.IsNull();
}
由于传递给映射函数的cat
是null
,导致失败的行是product.Category.IsNotNull();
。
我还向Assert类添加了此方法:
public static void IsNotNull(this object obj)
{
if (obj == null)
{
throw new ApplicationException("Expected not null");
}
}
autocrlf = false
,请将此文件(https://gist.github.com/2802523#file_the+original+guy+used+autocrlffalse)复制粘贴为`.gitattributes` *如果他使用了autocrlf = true
,请将此文件(https://gist.github.com/2802523#file_the+original+guy+used+autocrlftrue)复制粘贴为`.gitattributes` - Ana Betts