Linq手动添加EntitySet关系需要注意的地方

    public partial class Employee
    {
        partial void OnCreated()
        {
            this._ExTable = new EntitySet<ExTable>(null, null);
        }

        private EntitySet<ExTable> _ExTable;
        [Association(Storage = "_ExTable", ThisKey = "EmployeeId", OtherKey = "EmployeeId")]
        public EntitySet<ExTable> ExTable
        {
            get { return this._ExTable; }
            set { this._ExTable = value; }
        }
    }

一定要在OnCreated函数中进行初始化

否则在InsertOnSubmit时会引发异常

 

你可能感兴趣的:(Linq手动添加EntitySet关系需要注意的地方)