Afs*_*bbi 6 c# nhibernate dynamic nhibernate-mapping
如果我没有TRootEntity,我怎么能调用以下方法,但只有它TYPE:
public void Class<TRootEntity>(Action<IClassMapper<TRootEntity>> customizeAction) where TRootEntity : class;
最终目标是运行以下代码
var mapper = new ModelMapper();
mapper.Class<MyClass>(ca =>
{
ca.Id(x => x.Id, map =>
{
map.Column("MyClassId");
map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
});
ca.Property(x => x.Something, map => map.Length(150));
});
Run Code Online (Sandbox Code Playgroud)
它用于创建动态NHibernate HBM.这里有更多信息
Mar*_*mić 10
您不能通过传递运行时类型来编写要运行的通用方法.
泛型需要在编译时具有类型.
您可能需要使用反射(请参阅Ferreira先生的回答,指出如何做到这一点).