我正在尝试使用我们用来摆脱 Fluent NHibernate 的新的 loquacious 类映射功能。但是我对如何将类映射到配置感到困惑。我已经阅读了 F Maulo 的博客 ( http://fabiomaulo.blogspot.com/2011/04/me-on-fluent-nhibernate.html ),但我似乎无法让它工作。你们有没有关于如何将其添加到 NH 配置的信息?
问候,
根据 react 找到答案
foreach (string mappingAssembly in MappingsAssembly.Split(','))
{
if (string.IsNullOrEmpty(mappingAssembly)) continue;
Assembly assembly = Assembly.Load(mappingAssembly);
types.AddRange(assembly.GetTypes());
// configuration.AddAssembly(assembly);
}
configuration.DataBaseIntegration(x => GetDatabaseConfig(x));
ModelMapper mapper = new ModelMapper();
mapper.AddMappings(types);
var compiledMapping = mapper.CompileMappingForAllExplicitAddedEntities();
configuration.AddMapping(compiledMapping);
最佳答案
您可以尝试以下方法:
ModelMapper mapper = new ModelMapper();
// your mappings by code
Type[] types = new Type[] {}; // your mapped types here
// compile mappings
HbmMapping mapping = mapper.CompileMappingFor(types);
// create configuration
Configuration cfg = new Configuration();
// add mappings to config
cfg.AddDeserializedMapping(hbm,"documentname");
请记住,通过代码进行映射会给您带来很多新的可能性:例如:您可以使用 Assembly.GetTypes() 获取映射类型的列表。
关于c# - 在 NHibernate 中使用冗长的类映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569916/