简体   繁体   中英

Updating a complex data entity using Entity Framework

I am using MVC3, C# 4.0 and Entity Framework in Visual Studio 2010. I have a complex data entity (one base type which contains two sub-entities; each of these then contain further entities).

I can see how to do a bulk update of everything but wonder what is the best practice for updating this when only a few fields may have changed.

Thanks in advance

Usually I good idea in such cases is to define a viewmodel which represents the data you get as an input from the user interface. This could be a flat representation of your complex graph. And then in your repository or better in your domain layer there could be a mapping or a handling method/class that fills your modelle or does batch/bulk updates etc...

So usually have some sort of class (or more) in the middle helps usually...

That are my 2 cents without knowing to much of your application architecture...

If the properties of multiple sub entities have changed, I would handle it as an update to the complex data entity. If only one of the sub entities needs to be updated, then I would handle it as an update to only that specific entity. It's really a case by case basis type of situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM