Code First adding to collections? How to use Code First with repositories?

前端 未结 6 1328
执笔经年
执笔经年 2020-12-17 14:58

EDIT: This happen only on larger scale projects with repositories. Is there anybody using EF4 with CodeFirst approach and using repositories? Please advise me.

Hi. I

6条回答
  •  温柔的废话
    2020-12-17 15:39

    The problem in this instance is that change tracking proxies are being generated because all the properties on your class are marked as virtual. By convention this triggers Change Tracking Proxy generation.

    So you can either remove virtual keyword from one or more properties or simply tell the context not to generate change tracking proxies as per Working with POCO Entities.

    var ctx = new MyDbContext();
    ctx.Configuration.ProxyCreationEnabled = false;
    

提交回复
热议问题