如果我有以下内容(为简洁而减少)
public class TempCartMap : ClassMap<TempCart>
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Products); // < This one
}
[Serializable]
public class TempCart {
public TempCart(){
Products = new List<int>();
}
public virtual IList<int> Products { get; set; }
}
我看过(http://www.philliphaydon.com/2012/06/using-nhibernate-with-servicestack/)和(http://www.philliphaydon.com/2012/03/ormlite-blobbing-done-with-nhibernate-and-serialized-json/),但有一种更简单,更简单,更快捷的方式来获得NHibernate序列化&amp;如上所述反序列化列。 似乎过度杀伤以创建新的IUserType类等等。
答案 0 :(得分:1)
您还可以将Products-list存储为单独的表:
public class TempCartMap : ClassMap<TempCart>
{
Id(x => x.Id).GeneratedBy.Identity();
HasMany(x => x.Products)
.Element("product_number")
.KeyColumn("temp_cart_id")
.Table("temp_cart_products")
;
}
只是为了澄清这个问题:是不是有理由不这样做?