问题描述
我在没有IDE的情况下输入了这个简化的示例,因此请原谅任何语法错误。当我尝试自动执行此操作时,当我尝试编译映射时,我得到一个FluentConfigurationException -
I typed this simplified example without the benefit of an IDE so forgive any syntax errors. When I try to automap this I get a FluentConfigurationException when I attempt to compile the mappings -
我想如果我要解决这个问题,我会得到遇到 IEmployer
的引用时出现类似的错误。我并不反对手动创建一个ClassMap,但我更喜欢AutoMapper。
I imagine if I were to resolve this I'd get a similar error when it encounters the reference to IEmployer
as well. I'm not opposed to creating a ClassMap manually but I prefer AutoMapper doing it instead.
public interface IEmployer
{
int Id{ get; set; }
IList<IEmployee> Employees { get; set; }
}
public class Employer: IEmployer
{
public int Id{ get; set; }
public IList<IEmployer> Employees { get; set; }
public Employer()
{
Employees = new List<IEmployee>();
}
}
public interface IEmployee
{
int Id { get; set; }
IEmployer Employer { get; set; }
}
public class Employee: IEmployee
{
public int Id { get; set;}
public IEmployer Employer { get; set;}
public Employee(IEmployer employer)
{
Employer = employer;
}
}
我尝试过使用 .IncludeBase< IEmployee>()
但无济于事。它的行为就像我从未调用过IncludeBase一样。
I've tried using .IncludeBase<IEmployee>()
but to no avail. It acts like I never called IncludeBase at all.
唯一的解决方案是不使用我的域实体中的接口还是回退到手动定义的ClassMap?
Is the only solution to either not use interfaces in my domain entities or fall back on a manually defined ClassMap?
这两个选项都会对我的应用程序的设计方式造成严重问题。在完成所有功能的实现之前,我忽略了持久性,这是一个我不会再重复的错误: - (
Either option creates a significant problem with the way my application is designed. I ignored persistence until I had finished implementing all the features, a mistake I won't be repeating again :-(
推荐答案
这是不是Fluent或其AutoMapper强加的限制,而是NHibernate本身的限制。
It's not a restriction imposed by Fluent or its AutoMapper, but by NHibernate itself.
因此我不认为你会用手动类地图到达那里。你会必须丢失属性和列表定义中的接口。您可以保留接口,但映射的属性和集合必须使用NHibernate知道的具体类型。
I therefore don't think you'd get there with the manual class map. You'll have to lose the interfaces in the property and list definitions. You can keep the interfaces, but mapped properties and collections must use the concrete types of which NHibernate knows.
这篇关于可以流畅的NHibernate的AutoMapper处理接口类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!