Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Asp.net和fluent nhibernate中的子级更新父表_C#_Asp.net_Fluent Nhibernate_Unitofworkapplication - Fatal编程技术网

C# 从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 =>

我正在尝试从Asp.net中的子视图更新子表中引用的父表中的数据

我使用Fluent Nhibernate映射了这些表

在子表中,映射如下所示:

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());