使用它能够流利的AutoPersistenceModel但与渴望的装载在一个单一的对象
-
05-07-2019 - |
题
我很流利使用它能够以自动地图我实体。
这是代码,我在使用的自动映射:
new AutoPersistenceModel()
.AddEntityAssembly(Assembly.GetAssembly(typeof(Entity)))
.Where(type => type.Namespace.Contains("Domain") && type.BaseType != null && type.BaseType.Name.StartsWith("DomainEntity") && type.BaseType.IsGenericType == true)
.WithSetup(s => s.IsBaseType = (type => type.Name.StartsWith("DomainEntity") && type.IsGenericType == true))
.ConventionDiscovery.Add(
ConventionBuilder.Id.Always(x => x.GeneratedBy.Increment())
);
这工作就好了。但现在我需要有渴望的装载在一个单一目的,我域。发现 这个答案.但是当我增加的线路 .ForTypesThatDeriveFrom<IEagerLoading>(map => map.Not.LazyLoad())
代码并运行它,我得到以下例外:
- 错误,而试图建立的映射文件IEagerLoading
请注意我用一个接口(IEagerLoading
)标记的对象,我想渴望负荷。
任何人都可以帮助如何做到这一点?请记住我想要继续自动行映射的功能。
感谢
解决方案
问题你打的是, ForTypesThatDeriveFrom<T>
是有点误导性命名,那它真正的意思 ForMappingsOf<T>
, ,因此,它试图找到一个 ClassMap<IEagerLoading>
这显然不存在。
我认为你应该能够处理这一定义 IClassConvention
.这是关闭我的头顶,但是应该的工作:
public class EagerLoadingConvention : IClassConvention
{
public bool Accept(IClassMap target)
{
return GetType().GetInterfaces().Contains(typeof(IEagerLoading));
}
public void Apply(IClassMap target)
{
target.Not.LazyLoad();
}
}
不隶属于 StackOverflow