NHibernate update reference

十年热恋 提交于 2019-12-04 17:24:32
dotjoe

Updated: Session.Load is the correct answer

product.Category = session.Load<Category>(2);

session.Save(product);

It looks like you might be able to using the Session.Load(id) functionality.

Session.Load is a special method that returns a proxy with the ID until you request another property at which point it loads. It throws an error if there is no item matching the ID. Try something like:

product.Category = Session.Load<Category>(2); //2 being the new category ID

Session.SaveOrUpdate(product);

I just did a little testing and it did not seem to pull back the entire Category.

Use NH's EnumStringType<T> to map your Category as an enum to the respective database value (which can be a string or a number). You'll find quite a few usage examples, if you google for it.

HTH!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!