我有以下代码
[Class]
[Discriminator(Column="MachineType",TypeType=typeof(string))]
public abstract class Machine
{
[Property]
public string Name{get;set;}
}
[Subclass(DiscriminatorValue="Heavy",ExtendsType=typeof(Machine))]
public class HeavyMachine : Machine
{
[Property]
public int Weight { get; set; }
}
[Subclass(DiscriminatorValue="Fast",ExtendsType=typeof(Machine))]
public class FastMachine : Machine
{
[Property]
public float Speed { get; set; }
}
[Class]
public class Module
{
List<Machine> machines = new List<Machine>();
[Bag(Name = "Machines", Cascade = "all", Lazy = false, Inverse=true)]
[Key(1, Column = "Machine")]
[OneToMany(2, ClassType = typeof(Machine))]
public IList<Machine> Machines
{
get
{
return machines.AsReadOnly();
}
private set
{
machines = value.ToList();
}
}
}
使用上面的代码,我没有得到任何错误,但是在从数据库检索对象之后,模块中的机器集合仍然是空的。机器(及其子类)的映射似乎没有问题,因为正确返回了Machine类型的属性。
映射抽象类集合需要哪些Nhibernate.Mapping.Attributes?
提前谢谢!