How can I use a variable as type for calling an NHibernate query? My code looks (simplyfied) like this:
public string MyFunction()
{
var myVar = typeof(MyModel);
var myVar2 = ExecQuery<myVar>();
}
private List<T> ExecQuery<T>()
{
var result = sessionService.GetDefaultSession()
.Query<T>()
.ToList();
return result;
}
MyModel looks as follows:
public class MyModel
{
public virtual int Id {get; set;}
public virtual string Name {get; set;}
}
And the mapping:
public class MyModelMapping : ClassMapping<MyModel>
{
public MyModelMapping()
{
Id(a => a.Id, b => b.Generator(Generators.Identity));
Property(a => a.Name, b =>
{
b.NotNullable(true);
});
}
}
I get the error: myVar
is a variable but is used like a type.
Any ideas? Thanks:)