交换成员,确定对象的证书是不可能的。尝试使用新证书添加新对象

时间:2014-08-06 08:14:02

标签: c# sql linq

你好!当我尝试使用帮助“linq to sql”更新我的表时,我得到一个异常,其中包含一条消息,上面写着这样的消息

  1. 无法交换成员,确定对象的证书。尝试使用新证书添加新对象,然后删除现有对象。

  2. 在DB中构建我的表是[Field1(int,PK),Field2(varchar(15),PK),Field3(varchar(32),PK),Field4(int,PK)],那里没有任何约束和触发器。

  3. 在MSSQL中,我可以进行任何操作,例如"更新","插入"和"删除",但在我的应用程序中,我只能插入和删除我的记录

  4. 我的实体类,根据DB

  5. 中的表格
    [DataContract]
    [Table(Name = "dbo.MyTable")]
    public class MyTable: DataContext
    {
        private int _Field1;
    
        private string _Field2;
    
        private string _Field3;
    
        private int _Field4;
    
        private EntityRef<MyTable1> _MyTable1;
    
        private EntityRef<MyTable2> _MyTable2;
    
        public event PropertyChangingEventHandler PropertyChanging;
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
    
        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }
    
        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    
        private void Initialize()
        {
            this._MyTable1 = new EntityRef<MyTable1>();
            this._MyTable2 = new EntityRef<MyTable2>();
        }
    
        public MyTable()
        {
            Initialize();
        }
    
        [Association(IsForeignKey = true, Name = "MyTable_MyTable1", OtherKey = "Field4", Storage = "_MyTable1", ThisKey = "Field4")]
        public MyTable1 MyTable1
        {
            get { return this._MyTable1.Entity; }
            set
            {
                MyTable1 entity = this._MyTable1.Entity;
                if (entity == value && this._MyTable1.HasLoadedOrAssignedValue)
                    return;
                this.SendPropertyChanging();
                if (entity != null)
                {
                    this._MyTable1.Entity = (MyTable1)null;
                }
                this._MyTable1.Entity = value;
                if (value != null)
                {
                    this.Field4 = value.Field4;
                }
                else
                {
                    this.Field4 = 0;
                }
    
                this.SendPropertyChanged("MyTable1");
            }
        }
    
        [Association(IsForeignKey = true, Name = "MyTable_MyTable2", OtherKey = "Field1", Storage = "_MyTable2", ThisKey = "Field1")]
        public MyTable2 MyTable2
        {
            get
            {
                return this._MyTable2.Entity;
            }
            set
            {
                MyTable2 entity = this._MyTable2.Entity;
                if (entity == value && this._MyTable2.HasLoadedOrAssignedValue)
                    return;
                this.SendPropertyChanging();
                if (entity != null)
                {
                    this._MyTable2.Entity = (MyTable2)null;
                }
                this._MyTable2.Entity = value;
                if (value != null)
                {
                    this.Field1 = value.Field1;
                }
                else
                {
                    this.Field1= 0;
                }
    
                this.SendPropertyChanged("MyTable2");
            }
        }
    
        [Column(DbType = "Int", Storage = "_Field1", IsPrimaryKey = true, CanBeNull = false)]
        [DataMember(Order = 1)]
        public int Field1
        {
            get
            {
                return this._Field1;
            }
            set
            {
                if ((this._Field1 != value))
                {
                    this._Field1 = value;
                }
            }
        }
    
        [Column(DbType = "VARCHAR(15)", Storage = "_Field2", IsPrimaryKey = true, CanBeNull = false)]
        [DataMember(Order = 2)]
        public string Field2
        {
            get
            {
                return this._Field2;
            }
            set
            {
                if ((this._Field2 != value))
                {
                    this._Field2 = value;
                }
            }
        }
    
        [Column(DbType = "VARCHAR(32)", Storage = "_Field3", IsPrimaryKey = true, CanBeNull = false)]
        [DataMember(Order = 3)]
        public string Field3
        {
            get
            {
                return this._Field3;
            }
            set
            {
                if ((this._Field3 != value))
                {
                    this._Field3 = value;
                }
            }
        }
    
        [Column(DbType = "Int", Storage = "_Field4", IsPrimaryKey = true, CanBeNull = false)]
        [DataMember(Order = 4)]
        public int Field4
        {
            get
            {
                return this._Field4;
            }
            set
            {
                if ((this._Field4 != value))
                {
                    this._Field4 = value;
                }
            }
        }
    }
    

    }

0 个答案:

没有答案