开发者

NHibernate. Initiate save collection at saving parent

开发者 https://www.devze.com 2022-12-24 00:02 出处:网络
I\'ve got a problem at saving my entity. MApping: ?xml version=\"1.0\" encoding=\"utf-8\" ?> <hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\"

I've got a problem at saving my entity. MApping:

 ?xml version="1.0" encoding="utf-8" ?>
 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="Clients.Core"
               namespace="Clients.Core.Domains">
<class name="Sales, Clients.Core" table='sales'>
   <id name="Id" unsaved-value="0">
  <column name="id" not-null="true"/>
  <generator class="native"/>
</id>
<property name="Guid">
  <column name="guid"/>
</property>
<set name="Accounts" table="sales_users" lazy="false">
  <key column="sales_id" />
  <element column="user_id" type="Int32" />
</set>

Domain:

public class Sales : BaseDomain
{
    ICollection<int> accounts = new List<int>();
    public virtual ICollection<int> Accounts
    {
        get { return accounts; }
        set { accounts = value; }
    }
    public Sales() { }           
}

When I save Sales object Account collection don't save at sales_users table. What s开发者_如何转开发hould I do for saving it? Please don't advice me use classes inside List

Thanks a lot.


Looks like you're missing the cascade attribute when you map the collection.

0

精彩评论

暂无评论...
验证码 换一张
取 消