C# 从Asp.net和fluent nhibernate中的子级更新父表
我正在尝试从Asp.net中的子视图更新子表中引用的父表中的数据 我使用Fluent Nhibernate映射了这些表 在子表中,映射如下所示:C# 从Asp.net和fluent nhibernate中的子级更新父表,c#,asp.net,fluent-nhibernate,unitofworkapplication,C#,Asp.net,Fluent Nhibernate,Unitofworkapplication,我正在尝试从Asp.net中的子视图更新子表中引用的父表中的数据 我使用Fluent Nhibernate映射了这些表 在子表中,映射如下所示: public class ChildMap: ClassMap<Child> { public ChildMap() { Id(i => i.childID).Not.Nullable(); Map(i => i.childValue1); Map(i =>
public class ChildMap: ClassMap<Child>
{
public ChildMap()
{
Id(i => i.childID).Not.Nullable();
Map(i => i.childValue1);
Map(i => i.childValue2);
Map(i => i.childValue3);
References(i => i.parent, "parentID").Cascade.All();
}
使用上面的代码,当我尝试更新子表中的值时,它会起作用。但是,如果我试图将更改保存到父表中,它将不起作用
你有办法解决这个问题吗
谢谢。好的。。我只是回答了我自己的问题。基本上,只需添加父级的表名即可
UpdateModel(child.parent, "Parent", new[] { "child.parent.parentValue1", "child.parent.parentValue2", "child.parent.parentValue3" }, collection.ToValueProvider());
耶
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
using (var tr = UnitOfWork.CurrentUnitOfWork.BeginTransaction())
{
try
{
var child= Registry.Childs.Get(id);
//This update works
UpdateModel(child, new[] { "childValue1", "childValue2", "childValue3" }, collection.ToValueProvider());
//This update on the parent doesn't work
UpdateModel(child.parent, new[] { "child.parent.parentValue1", "child.parent.parentValue2", "child.parent.parentValue3" }, collection.ToValueProvider());
tr.Commit();
}
catch (Exception)
{
tr.Rollback();
throw;
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
UpdateModel(child.parent, "Parent", new[] { "child.parent.parentValue1", "child.parent.parentValue2", "child.parent.parentValue3" }, collection.ToValueProvider());