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时会引发异常

 

posted @ 2013-05-30 17:18  I'm CY  阅读(335)  评论(0编辑  收藏  举报