English 中文(简体)
Nhibernate更新-用于更新实体上的子项的解决方案?
原标题:Nhibernate Updating - Solutions for updating children on an entity?
  • 时间:2010-10-16 04:43:04
  •  标签:
  • nhibernate

寻求有关如何更新实体集合的一些建议。在网络应用程序中,我们有一个多选列表框,允许用户从可用实体列表中分配和删除子实体。用户将选择要与父级关联的相关子级。即它可能属于多个类别的产品。一旦用户满意,他们就会提交,我们会更新实体。

将性能考虑在内,更新(删除已删除的子项、添加新子项)到集合的首选方式是什么。我不想运行几个sql语句来获取每个子项并将其添加到父项中。

干杯

附加映射:

 public class ParentMap : EntityMapping<Parent>
    {
        public ParentMap()
        {
            Map(x => x.Name);
            HasMany(x => x.Children)
                .Cascade.AllDeleteOrphan()
                .Access.LowerCaseField(Prefix.Underscore);
        }
    }

    public class ChildMap : EntityMapping<Child>
    {
        public ChildMap()
        {
            References(x => x.Parent);
        }
    }

 public abstract class EntityMapping<TEntity> : ClassMap<TEntity> where TEntity : EntityBase
    {
        protected EntityMapping()
        {
            Id(x => x.Id, "Id")
                .UnsavedValue("00000000-0000-0000-0000-000000000000")
                .GeneratedBy.GuidComb();
            OptimisticLock.Version();
            Version(entity => entity.Version);
        }
    }
问题回答

在父实体和子实体之间建立级联关系,并强制其执行更新、删除等所有操作。您必须在HBM映射文件中定义级联行为。有关更多信息:http://nhibernate.info/doc/nh/en/index.html#mapping-声明映射





相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签