Ho un problema con MultiMaps in dapper che prova a dividere sulla colonna che contiene NULL
. Dapper sembra non istanziare l'oggetto e la mia funzione di mappatura riceve null
invece di oggetto.Dapper MultiMap non funziona con splitOn con valore NULL
Ecco il mio nuovo 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();
}
La linea che non riesce è product.Category.IsNotNull();
dovuto al fatto che cat
passato alla funzione di mappatura è null
.
Ho anche aggiunto di questo metodo per affermare classe:
public static void IsNotNull(this object obj)
{
if (obj == null)
{
throw new ApplicationException("Expected not null");
}
}
Mi piacerebbe tanto aiutare, ping a Paul su Twitter che scrive github per Windows. So che stanno lavorando duramente per ottenere questa linea che termina il problema trattabile –
@ Samamaffron - grazie per il tuo commento. Se me lo fai sapere una volta risolto, posso spingere le mie modifiche. Potresti copiare il test dal mio post, però - è abbastanza ovvio dove dovrebbero andare le modifiche ;-) PS. Amo Github per Windows. Fammi sapere se potrei essere di qualche aiuto con i test. –
Ho inviato un PR per Dapper che dovrebbe far scomparire questi problemi di fine linea.Fammi sapere se si presentano ancora. Morale della trama: * Copia-incolla [questo file] (https://gist.github.com/2802523#file_the+original+guy+used+autocrlffalse) come '.gitattributes' se il tipo originale ha usato' autocrlf = false '* Copia-Incolla [questo file] (https://gist.github.com/2802523#file_the+original+guy+used+autocrlftrue) come' .gitattributes' se ha usato 'autocrlf = true' –