KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a problem with MultiMaps in dapper trying to split on column that contains NULL . Dapper seems not to instantiate object and my mapping function receives null instead of object. Here's my new test: 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(); } The line that fails is product.Category.IsNotNull(); due to the fact that cat passed to mapping function is null . I've also added this method to Assert class: public static void IsNotNull(this object obj) { if (obj == null) { throw new ApplicationException("Expected not null"); } }
Tags (comma-separated)
Save Edits
Cancel