【发布时间】:2013-07-17 14:14:31
【问题描述】:
我有一个带有一些继承的模型,它使用 nhibernate 来持久化数据库。使用流利的 nhibernate 的 nhibernate 映射工作正常,但我有一个场景,我需要为现有的父母保存一个孩子。我的模型如下所示:
public class Item
{
public long Id { get; set; }
public string Name { get; set; }
// other properties
}
public class ItemCommercial : Item
{
public decimal Value { get; set; }
// other properties
}
在我的数据库中,各个表通过Id <-> Id 关联(一对一)。
我想知道,如何只为数据库上现有的Item 保存一个ItemCommercial 实例。我有项目的 ID,但我不知道如何说 nhibernate 只说孩子,而是创建一个新项目,例如:
session.Save(itemCommercialObj); // will create a Item and ItemCommercial with the same Id
谢谢。
【问题讨论】:
-
也许您可以在
ItemCommercial中手动编写函数,女巫将返回带有您想要的数据的Item对象。所以如果你打电话给Item i = itemCommercialObj.ConvertMyselfToItem()你会得到想要的对象 -
不,我不能,我必须使用我的 ORM,因为它将被其他不同的数据库使用。
标签: c# .net nhibernate inheritance hql