简体   繁体   English

使用Entity Framework更新复杂数据实体

[英]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). 我在Visual Studio 2010中使用MVC3,C#4.0和Entity Framework。我有一个复杂的数据实体(一个基本类型包含两个子实体;每个子实体都包含其他实体)。

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. 通常我在这种情况下的好主意是定义一个viewmodel,它表示从用户界面获得的数据。 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... 这是我的2美分而不了解您的应用程序架构...

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. 这实际上是一个案例基础类型的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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