Disconnected Behavior of Entity Framework when Updating Object Graph

前端 未结 3 2012
臣服心动
臣服心动 2021-01-21 14:54

I\'m currently working with a project that use following technologies.

  1. ASP.net MVC - presentation Layer
  2. Data Service Layer - (WCF)
  3. Data Transfer
3条回答
  •  花落未央
    2021-01-21 15:30

    There are not many option to solve it. EF doesn't have any direct support for updating disconnected object graphs. You must code your update logic and there are generally two ways how to do it:

    • When you receive updated user from the service request you will call database and fetch current database state = user with all affected relations. You will use database version and updated version to build valid change set so at the end EF will update, insert and delete only data which have really changed.
    • You will modify your DTOs to transport state as well and your client will be responsible for setting the type of modification he did on the DTO. You will use this information to correctly configure ChangeTracker for every received entity.

提交回复
热议问题