如何使用Entity Framework从数据库更新模型的一个表? [英] How to update only one table for model from database with Entity Framework?

查看:565
本文介绍了如何使用Entity Framework从数据库更新模型的一个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用实体框架从db生成的模型。当数据库发生任何变化时,我从数据库更新模型以获取模型的更改。但此更新适用于模型中包含的所有实体(表)。

I have a model generated from db with Entity Framework. When I have any change in database, I update model from database to get the change in model. But this update is applied to all entities (tables) included in model.

现在我在表Tab1中添加一个新列。我不想将模型从数据库更新为我不想包含在模型中的一些其他更改。我可以手动在实体Tab1的模型中添加新的属性。那么它会导致映射错误。

Now I add a new column in a table Tab1. I don't want to update model from database as some other changes that I don't want to include in model. I can add the new property in model for entity Tab1 manually. then it caused mapping error.

所以我需要更新表$ code> Model.Store 以包含新的列。这意味着我只想为 Tab1 更新模型。

So I need to update Model.Store for the table to include the new column. It means I want to update model only for Tab1.

我该怎么做?

推荐答案

EDMX文件是一个组合3个不同部分的XML文件,构成了整个事情。如果您右键单击EDMX文件并选择打开... XML编辑器,您将看到3个不同的部分:

The EDMX file is an XML file that is a combination of 3 different parts that make up the whole thing. If you right-click on your EDMX file and choose "Open with... XML Editor" you'll see the 3 different sections:


  • < edmx:ConceptualModels>

  • < edmx:StorageModels>

  • < edmx:Mappings>

  • <edmx:ConceptualModels>
  • <edmx:StorageModels>
  • <edmx:Mappings>

这些部分可以手动编辑,风险自负! :-)

这样你只能修改你需要的东西。

These sections can be edited manually, at your own risk! :-)
That way you can modify only what you need to.

请注意,还可以生成CSDL,SSDL& MSL文件,而不是将它们嵌入到二进制文件中,通过将模型的Meta Artifact Processing属性更改为复制到输出目录。

Note that it's also possible to generate CSDL, SSDL & MSL files rather than having them embedded in the binary file, by changing the "Meta Artifact Processing" property of your model to "Copy to Output Directory".

如果你不想手动执行此操作,还有 Huagati DBML / EDMX工具,它是免费的,您可以从 huagati官方网站或从 visual studio gallery ,这是一个Visual Studio插件,可让您选择需要完成的更改。

If you don't want to do this manually, there's the Huagati DBML/EDMX tool, it is free and you can download it from huagati official site or from visual studio gallery, which is a Visual Studio plugin that allows you to select what changes need to be done.

这篇关于如何使用Entity Framework从数据库更新模型的一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆