Entity Framework 6.1 Updating a Subset of a Record

前端 未结 3 1389
暖寄归人
暖寄归人 2021-02-19 02:06

I have a view model that encapsulates only some of the database model properties. These properties contained by the view model are the only properties I want to update

3条回答
  •  忘了有多久
    2021-02-19 02:50

    (Edited for clarity)

    The context must have a complete copy of the object to enforce business rules. This can only happen if the attached object has all the necessary properties populated or the partial view is merged with a complete copy before updating.

    I believe that what you want to do is conceptually impossible: doing updates like this will require either a preserved pre-change copy, or two queries to the database because the business layer needs a full copy of the object for validation.

提交回复
热议问题