Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Created September 19, 2014 06:38
Show Gist options
  • Save hoangitk/77329abb996518932184 to your computer and use it in GitHub Desktop.
Save hoangitk/77329abb996518932184 to your computer and use it in GitHub Desktop.
public static class NhTransformers
{
public static readonly IResultTransformer ExpandoObject;
static NhTransformers()
{
ExpandoObject = new ExpandoObjectResultSetTransformer();
}
private class ExpandoObjectResultSetTransformer : IResultTransformer
{
public IList TransformList(IList collection)
{
return collection;
}
public object TransformTuple(object[] tuple, string[] aliases)
{
var expando = new ExpandoObject();
var dictionary = (IDictionary<string, object>)expando;
for (int i = 0; i < tuple.Length; i++)
{
string alias = aliases[i];
if (alias != null)
{
dictionary[alias] = tuple[i];
}
}
return expando;
}
}
}
public static class NHibernateExtensions
{
public static IList<dynamic> DynamicList(this IQuery query)
{
return query.SetResultTransformer(NhTransformers.ExpandoObject)
.List<dynamic>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment