Different result on DBNull from Sync/Async calls

Hello,
I’ve noticed a strange behavior when getting data from a Select vs SelectAsync

my code snippet is

var dbFactory = new OrmLiteConnectionFactory(@"<connectionstring>",     SqlServer2012Dialect.Provider);
using (var db = dbFactory.Open())
{
var q = db.From<dynamic>();
q.FromExpression = " FROM function(2)";
q = q.Select("*");

	var result = await db.SelectAsync(q);
	result.ToJson().Dump("ServiceStack");
}

Here’s the result

Select

[{"NOME_SERIE":"Strumenti azionari","ORDNUM":4,"VALORE_SERIE":0.26,"VALORE_LIMITE":0.60,"COLORE_SERIE":null},{"NOME_SERIE":"Strumenti obbligazionari di stato e assimilati e sovrannazionali oltre i 18 mesi (in EUR, no strutturati)","ORDNUM":1,"VALORE_SERIE":0.27,"VALORE_LIMITE":0.60,"COLORE_SERIE":null}]

SelectAsync

[{"NOME_SERIE":"Strumenti azionari","ORDNUM":4,"VALORE_SERIE":0.26,"VALORE_LIMITE":0.60,"COLORE_SERIE":{"__type":"System.DBNull, mscorlib"}},{"NOME_SERIE":"Strumenti obbligazionari di stato e assimilati e sovrannazionali oltre i 18 mesi (in EUR, no strutturati)","ORDNUM":1,"VALORE_SERIE":0.27,"VALORE_LIMITE":0.60,"COLORE_SERIE":{"__type":"System.DBNull, mscorlib"}}] 

For now I’ve fixed using JsConfig.SerializeFn = x => null; but this is a global setting… if it’s not a bug (even if I don’t see the reason to have 2 different results), is there a way I can have this setting scoped?

Thanks
Paolo

Can you show which data structure do you use for these selects (most interested of which type is “COLORE_SERIE” defined), and serialization options you’re set before running the code?

Please never use db.From<dynamic> the Type should be a POCO Type, using dynamic is completely undefined behavior.

and what should i use if I’ve arbitrary columns returned from a sp o a function?

Just use Custom SQL directly