具有抽象基础的流畅自动映射也是模型的一部分

时间:2011-04-07 14:36:13

标签: nhibernate abstract fluent automapping base

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

我正在尝试根据以下想法为我的应用程序使用流畅的自动映射。

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类并使其无抽象,那就可以了。

我是否可以针对基类型公开实体上的属性,其中基数是否为抽象?

感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

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

AutoMap.AssemblyOf<Container>(cfg)
       .IncludeBase<Container>();