我用一堆列定义了我的实体并创建了映射。
public class PurchaseRecord {
public virtual int? Id {
get;
set;
}
public virtual DateTime? PurchasedDate {
get;
set;
}
public virtual string Comment {
get;
set;
}
public virtual IList<PurchaseRecordExtendedProperty> ExtendedPropertyValues {
get;
set;
}
public class PurchaseRecordMap : ClassMap<PurchaseRecord> {
public PurchaseRecordMap() {
Table("PurchaseRecords");
Id(x => x.Id, "RecordID").GeneratedBy.Identity();
Map(x => x.PurchasedDate, "PurchaseDate").Not.Nullable();
Map(x => x.Comment, "Comment");
HasMany(x => x.ExtendedPropertyValues).KeyColumn("ExtendedPropertyID").Cascade.All();
}
它在大多数情况下都很好用,但是在某些情况下我想跳过更新某些列(例如 child collection ExtendedPropertyValues
)。当我创建PurchaseRecord
对象时,我什至懒得加载ExtendedPropertyValues
. 但是如果属性为空,NHibernate 会尝试从数据库中删除子记录。
我知道有些情况ExtendedPropertyValues
永远不会改变。出于性能考虑,我不想加载我不需要的数据,如果我不需要更新,有没有办法强制 NH 跳过指定的属性?
感谢您的任何建议。