English 中文(简体)
同一标识的不同物体已经与会议错误有关。
原标题:A different object with same identifier was already associated with the session error

<>Scenario: 我有一个能够装载 la的客户物体。 我在整个方案中都把客户名单列入名单箱。 该司与该司有关系。 Claimant_Rel, Division_ Email_Rel and Email_Address Object. 所有这些关系都有<代码>Lazy = 真实性, Cascade = 许多RelationCascadeEnum.AllDeleteOrphan, Inverse = 真实。

<>可见> 当我使用新的会议时,我尝试并挽救会议给我留下错误的<代码>。 同一标识的不同物体已经与本届会议有关。 我曾试图利用林研中心在不使用新会议的情况下将名单退回,把其他物体加入到电话中,但我不敢肯定如何使用活性文献Linq<在加入时。

private Customer GetCustomer()
    {
       return (from x in ActiveRecordLinq.AsQueryable<Customer>()
         where x.Customer_ID == ((Customer)lst_customers.SelectedItem).Customer_ID 
         select x).First();
    }

产生错误的法规

using (new SessionScope())
                {
                //var sess = GetSession();
                //var customer =
                //    sess.CreateCriteria<Customer>("c").CreateCriteria("c.DivisionCustomer_Rels").List<Customer>().
                //        First();
                var customer = GetCustomer();
                    /* Ensure user wishes to commit the data. */

                    var result =
                        MessageBox.Show(
                            @"You are about to submit changes to customer: " + customer.CustomerName + @"." +
                            Environment.NewLine + Environment.NewLine +
                            @"Submit Changes?", @"Submit Customer Changes", MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        customer.CustomerName = txt_custName.Text;
                        customer.NamcisNumber = Convert.ToInt32(txt_namcis.Text);
                        customer.DCA = chk_dca.Checked;
                        customer.CustomerType = (CustomerType_Code) cmb_custType.SelectedItem;
                        customer.AOR = (AOR_Code) cmbAOR.SelectedItem;
                        customer.CSRep = (CSRep_Code) cmbCSRep.SelectedItem;
                        customer.DivisionCustomer_Rels.Clear(); 
                        foreach (var t in lst_SectorCust.Items)
                        {
                            customer.DivisionCustomer_Rels.Add(new Division_Customer_Rel
                                                                   {
                                                                       Customer = customer
                                                                       ,
                                                                       Division = (Division_Code) t,
                                                                       MarkedForDeletion = false
                                                                   });
                        }
                        customer.CircuitCustomer_Rels.Clear();
                        foreach (var t in lst_Circuit.Items)
                        {
                            customer.CircuitCustomer_Rels.Add(new Circuit_Customer_Rel
                                                                  {
                                                                      Circuit = (Circuit) t,
                                                                      Customer = customer,
                                                                      MarkedForDeletion = false
                                                                  });
                        }
                        customer.EmailAddresses.Clear();
                        foreach (var t in lst_email.Items)
                        {
                            var temp = (Email_Address)t;
                            temp.Customer = customer;
                            customer.EmailAddresses.Add(temp);

                        }
                        ////Need to manage the emails this way otherwise we recieve an error because of lazy loading
                        //foreach (var temp in lst_email.Items.Cast<Email_Address>())
                        //{
                        //    temp.Customer = customer;
                        //    if (!customer.EmailAddresses.Any(s=>temp.ToString().Equals(s.ToString())) && !customer.EmailAddresses.Contains(temp))
                        //    {
                        //        customer.EmailAddresses.Add(temp);
                        //    }

                        //}

                        //var text = IList<Email_Address> lst_email.Items;
                        //var tem = customer.EmailAddresses.Except(lst_email.Items);
                        //for (var i = customer.EmailAddresses.Count - 1; i >= 0;i-- )
                        //{
                        //    var temp = customer.EmailAddresses[i];

                        //    for (var j = 0; j < lst_email.Items.Count; j++)
                        //    {
                        //        if (temp.ToString()!=lst_email.Items[j].ToString())
                        //        {
                        //            customer.EmailAddresses.Remove(temp);
                        //        }
                        //    }
                        //}
                        customer.DivisionEmail_Rels.Clear(); 
                        customer.Save();
                        MessageBox.Show(@"Changes submitted.");
                    }
                    //SessionScope.Current
                }

电子邮件地址

   namespace Sens
{
    using System;
    using System.Collections.Generic;
    using Castle.ActiveRecord;

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

        public Email_Address()
        {
            DivisionEmail_Rels = new List<Division_Email_Rel>();
        }

        #endregion

        #region Properties

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

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

        [Property(Column = "[Email]", NotNull = true, Length = 100)]
        public string Email { get; set; }

        [BelongsTo(Column = "EmailType_ID")]
        public EmailType_Code EmailType { get; set; }

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

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

        #endregion

        #region HasMany DivisionEmail_Rels

        [HasMany(typeof(Division_Email_Rel), Lazy = false,Cascade=ManyRelationCascadeEnum.AllDeleteOrphan,Inverse=true)]
        public IList<Division_Email_Rel> DivisionEmail_Rels { get; set; }

        #endregion
    }
}

经常预算

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

                        }

如果有人能够解释,那将是巨大的。 我将这一点放在这里,希望这将节省下一位遇到这一错误的人的一些时间。

问题回答

驱逐者将“Email_Address”这一具体内容从NHibernate第一层藏匿处删除。

客户。 电子邮件:addresses 你删除了NHibernate第一层藏匿点的所有电子邮件地址。

然后,你从电子邮件的电子邮件清单中获取物品,并将这些物品作为新对象列入电子邮件。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签