Created
September 19, 2014 06:38
-
-
Save hoangitk/77329abb996518932184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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