0

好的,首先我希望这是有道理的。

我正在尝试基于以下想法为我的应用程序使用流利的自动映射。

public abstract class Container
{
  public virtual int Id {get; set};
  public virtual string Name {get; set;}
}

public class FirstSubClass : Container
{
   //properties and behaviour here
}

public class SecondSubClass : Container
{
  //properties of SecondSubclass Here
}

public class ProcessStep
{
   public virtual Container Source {get; set}
   public virtual Container Destination {get; set;}
}

但是,当我尝试生成架构或测试我的映射(使用 SQLite 或其他方式)时,它没有注意到:

NHibernate.MappingException:来自表 ProcessStep 的关联引用了一个未映射的类:......Entities.Container

如果我更改 Container 类并使其不是抽象的,它就可以工作。

我可以根据基本类型公开实体上的属性,而基本保持抽象吗?

任何帮助将不胜感激。

4

1 回答 1

4

默认情况下,Fluent Nhibernate 在生成映射时会忽略抽象基类。要包含它,您需要使用IncludeBase方法:

AutoMap.AssemblyOf<Container>(cfg)
       .IncludeBase<Container>();
于 2011-04-08T06:15:24.490 回答