我想在NHibernate中映射这样的类,但不为父类创建表。
public class CarService
{
public Guid CarId { get; set; }
public ICollection<Service> Services { get; protected set; }
public void Add(Service service)
{
if (this.Services.Any(s => s.Type == service.Type))
{
throw new Exception("service type already added");
}
this.Services.Add(service);
}
}
public class Service
{
public Guid ServiceId { get; set; }
public ServiceType Type { get; set; }
public string Prop2 { get; set; }
...
}因此,我只想为Child创建一个表,如下所示:
| CHILD |
|----------|
| ChildId |
| ParentId |
| Prop1 |
| Prop2 |
| ... |
|----------|在NHibernate中可以进行这样的映射吗?
编辑:我已经更新了我的对象模型。让父类拥有一些东西来保护我的模型的集成(来自DDD的聚合根)的主要原因。在我的模型中,我有CarService类,它将存储为car购买的所有服务,我想在我的模型中创建一些验证,以防止两次添加相同的服务类型。
发布于 2014-07-31 10:58:56
我认为这是不可能的。您总是可以在内存中构造父对象,但是NHibernate不会为您这样做。
https://stackoverflow.com/questions/25045488
复制相似问题