C# tiveRecordValidationBase { #区域构造函数 公共电子邮件地址() { DivisionEmail_Rels=新列表(); } #端区 #区域属性 [PrimaryKey(Column=“Email\u ID”)] //ReSharper禁用不一致命名 public int Email_ID{get;private set;} [BelongsTo(Column=“Customer\u ID”)] 公共客户客户{get;set;} [Property(Column=“[Email]”,NotNull=true,Length=100] 公共字符串电子邮件{get;set;} [BelongsTo(Column=“EmailType_ID”)] 公共电子邮件类型\代码电子邮件类型{get;set;} [Property(Column=“[ReceivesSENS]”,NotNull=true] 公共bool ReceivesSENS{get;set;} [属性(列=“[MarkedForDelete]”,NotNull=true)] 公共布尔标记为删除{get;set;} #端区 #该地区有许多地区 [HasMany(typeof(Division\u Email\u Rel),Lazy=false,Cascade=ManyRelationCascadeEnum.AllDeleteOrphan,Inverse=true)] 公共IList分区电子邮件{get;set;} #端区 } }

C# tiveRecordValidationBase { #区域构造函数 公共电子邮件地址() { DivisionEmail_Rels=新列表(); } #端区 #区域属性 [PrimaryKey(Column=“Email\u ID”)] //ReSharper禁用不一致命名 public int Email_ID{get;private set;} [BelongsTo(Column=“Customer\u ID”)] 公共客户客户{get;set;} [Property(Column=“[Email]”,NotNull=true,Length=100] 公共字符串电子邮件{get;set;} [BelongsTo(Column=“EmailType_ID”)] 公共电子邮件类型\代码电子邮件类型{get;set;} [Property(Column=“[ReceivesSENS]”,NotNull=true] 公共bool ReceivesSENS{get;set;} [属性(列=“[MarkedForDelete]”,NotNull=true)] 公共布尔标记为删除{get;set;} #端区 #该地区有许多地区 [HasMany(typeof(Division\u Email\u Rel),Lazy=false,Cascade=ManyRelationCascadeEnum.AllDeleteOrphan,Inverse=true)] 公共IList分区电子邮件{get;set;} #端区 } },c#,nhibernate,join,castle-activerecord,linq-to-nhibernate,C#,Nhibernate,Join,Castle Activerecord,Linq To Nhibernate,客户关系部 namespace Sens { using System; using Castle.ActiveRecord; [Serializable, ActiveRecord("dbo.Division_Customer_Rel")] public class Division_Customer_Rel : ActiveRecordValidationBase<Division_Customer_Rel> {

客户关系部

    namespace Sens
{
    using System;
    using Castle.ActiveRecord;

    [Serializable, ActiveRecord("dbo.Division_Customer_Rel")]
    public class Division_Customer_Rel : ActiveRecordValidationBase<Division_Customer_Rel>
    {
        #region Constructors

        #endregion

        #region Properties

        [PrimaryKey(Column = "Relationship_ID")]
// ReSharper disable InconsistentNaming
        public int Relationship_ID { get; private set; }
// ReSharper restore InconsistentNaming

        [BelongsTo(Column = "Customer_ID")]
        public Customer Customer { get; set; }

        [BelongsTo(Column = "Division_ID")]
        public Division_Code Division { get; set; }

        [Property(Column = "[MarkedForDeletion]", NotNull = true)]
        public bool MarkedForDeletion { get; set; }

        #endregion
    }
}
名称空间传感器
{
使用制度;
使用Castle.ActiveRecord;
[可序列化的ActiveRecord(“数据库部门客户关系”)]
公共类部门\客户\关系:ActiveRecordValidationBase
{
#区域构造函数
#端区
#区域属性
[PrimaryKey(Column=“Relationship_ID”)]
//ReSharper禁用不一致命名
公共int关系_ID{get;private set;}
//ReSharper还原不一致的命名
[BelongsTo(Column=“Customer\u ID”)]
公共客户客户{get;set;}
[BelongsTo(Column=“Division_ID”)]
公共除法\代码除法{get;set;}
[属性(列=“[MarkedForDelete]”,NotNull=true)]
公共布尔标记为删除{get;set;}
#端区
}
}
部门电子邮件

 #region namespace imports

using System;
using Castle.ActiveRecord;

#endregion

namespace Sens
{
    [Serializable, ActiveRecord("dbo.Division_Email_Rel")]
    public class Division_Email_Rel : ActiveRecordValidationBase<Division_Email_Rel>
    {
        #region Constructors

        #endregion

        #region Properties

        [PrimaryKey(Column = "Relationship_ID")]
// ReSharper disable InconsistentNaming
            public int Relationship_ID { get; private set; }

// ReSharper restore InconsistentNaming

        [BelongsTo(Column = "Email_ID", Cascade = CascadeEnum.All)]
        public Email_Address Email { get; set; }

        [BelongsTo(Column = "Division_ID")]
        public Division_Code Division { get; set; }

        [BelongsTo(Column = "Customer_ID")]
        public Customer Customer { get; set; }

        [Property(Column = "[MarkedForDeletion]", NotNull = true)]
        public bool MarkedForDeletion { get; set; }

        #endregion
    }
}
#区域名称空间导入
使用制度;
使用Castle.ActiveRecord;
#端区
名称空间传感器
{
[可序列化的ActiveRecord(“dbo.Division\u Email\u Rel”)]
公共类分区\u电子邮件\u Rel:ActiveRecordValidationBase
{
#区域构造函数
#端区
#区域属性
[PrimaryKey(Column=“Relationship_ID”)]
//ReSharper禁用不一致命名
公共int关系_ID{get;private set;}
//ReSharper还原不一致的命名
[BelongsTo(Column=“Email_ID”,Cascade=cascadenum.All)]
公共电子邮件地址电子邮件{get;set;}
[BelongsTo(Column=“Division_ID”)]
公共除法\代码除法{get;set;}
[BelongsTo(Column=“Customer\u ID”)]
公共客户客户{get;set;}
[属性(列=“[MarkedForDelete]”,NotNull=true)]
公共布尔标记为删除{get;set;}
#端区
}
}

在到处搜索答案后,我最终将其保存下来的方法是清除电子邮件地址,而不是清除它们

SessionScope.Current.Evict(customer.EmailAddresses);
                        foreach (var t in lst_email.Items)
                        {
                            var temp = (Email_Address)t;
                            temp.Customer = customer;
                            customer.EmailAddresses.Add(temp);

                        }

不知道为什么会这样,如果有人能解释的话,那就太好了。我在这里发布此消息,希望它能为下一个遇到此错误的人节省一些时间。

逐出操作将从NHibernate一级缓存中删除特定的“电子邮件地址”引用

从customer.emailAddresss中,您已删除NHibernate一级缓存中的所有电子邮件地址


然后,您将从lst_电子邮件中的电子邮件列表中获取项目,并将其作为新对象添加到客户的电子邮件地址中。

1。LINQtoSQL在这里必须做什么?这是一个完全不同的图书馆。2.您是否可以发布引发“具有相同标识符的不同对象已与会话关联”的代码?您是否也可以发布部门客户、部门电子邮件和电子邮件地址类的代码?@Mauricio Scheffer我将在周一发布代码(与工作相关)
    namespace Sens
{
    using System;
    using Castle.ActiveRecord;

    [Serializable, ActiveRecord("dbo.Division_Customer_Rel")]
    public class Division_Customer_Rel : ActiveRecordValidationBase<Division_Customer_Rel>
    {
        #region Constructors

        #endregion

        #region Properties

        [PrimaryKey(Column = "Relationship_ID")]
// ReSharper disable InconsistentNaming
        public int Relationship_ID { get; private set; }
// ReSharper restore InconsistentNaming

        [BelongsTo(Column = "Customer_ID")]
        public Customer Customer { get; set; }

        [BelongsTo(Column = "Division_ID")]
        public Division_Code Division { get; set; }

        [Property(Column = "[MarkedForDeletion]", NotNull = true)]
        public bool MarkedForDeletion { get; set; }

        #endregion
    }
}
 #region namespace imports

using System;
using Castle.ActiveRecord;

#endregion

namespace Sens
{
    [Serializable, ActiveRecord("dbo.Division_Email_Rel")]
    public class Division_Email_Rel : ActiveRecordValidationBase<Division_Email_Rel>
    {
        #region Constructors

        #endregion

        #region Properties

        [PrimaryKey(Column = "Relationship_ID")]
// ReSharper disable InconsistentNaming
            public int Relationship_ID { get; private set; }

// ReSharper restore InconsistentNaming

        [BelongsTo(Column = "Email_ID", Cascade = CascadeEnum.All)]
        public Email_Address Email { get; set; }

        [BelongsTo(Column = "Division_ID")]
        public Division_Code Division { get; set; }

        [BelongsTo(Column = "Customer_ID")]
        public Customer Customer { get; set; }

        [Property(Column = "[MarkedForDeletion]", NotNull = true)]
        public bool MarkedForDeletion { get; set; }

        #endregion
    }
}
SessionScope.Current.Evict(customer.EmailAddresses);
                        foreach (var t in lst_email.Items)
                        {
                            var temp = (Email_Address)t;
                            temp.Customer = customer;
                            customer.EmailAddresses.Add(temp);

                        }