NHibernate - 对象引用一个未保存的瞬态实例 - 在刷新之前保存瞬态实例 [英] NHibernate - object references an unsaved transient instance - save the transient instance before flushing
问题描述
我收到以下错误:
object references an unsaved transient instance - save the transient instance before flushing
我不想想保存瞬态实例.我正在尝试将验证结果发送回客户端:
I do not want to save the transient instance. I'm trying to send validation results back to the client:
if (MyObject.IsValid()) {
MyObjectRepo.Hydrate(MyObject);
return Json(MyObject);
}
else {
Dictionary<string, string> test = new Dictionary<string, string>();
test.Add("failure", "failure");
foreach (var a in MyObject.ValidationResults().ToList()) {
test.Add(a.PropertyName, a.Message);
}
return Json(test);
如果对象无效并且我没有测试字典和 foreach 语句(例如,只是发回一个失败字符串),它会正常工作.我在这方面发现的所有其他问题都与保存对象失败有关......对象无效,我不想保存它,只需发送失败验证的结果.谢谢!
If the object is not valid and I don't have the test dictionary and foreach statement (for example just sending back, a failure string), it'll work fine. All other questions I've found on this relate to failures saving the object ... the object is not valid and I do not want to save it, just send down the results of the failed validation. Thanks!
推荐答案
您是否在 ISession 中?如果是这样,也许做一个 transaction.RollBack()?
Are you inside an ISession? If so, perhaps do a transaction.RollBack()?
这篇关于NHibernate - 对象引用一个未保存的瞬态实例 - 在刷新之前保存瞬态实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!