简体   繁体   English

在实体框架中更新视图的问题

[英]Problems with updating Views in Entity Framework

For some reasons we need to update Views inside the Entity Framework . 由于某些原因,我们需要在Entity Framework内更新Views So we followed this solution on another question and it worked like a charm! 因此,我们在另一个问题上遵循了该解决方案 ,它的工作原理就像一个魅力!

BUT here is the problem: 但是这里是问题所在:
if we update our model (for some new fields or tables/views) the complete Mappings are destroyed and after updating we get the Warning 如果我们更新模型(对于某些新字段或表/视图),则完整的映射将被销毁,并且在更新后,我们会收到警告

Error 11007: Entity type 'UpdateView1' is not mapped. 错误11007:实体类型'UpdateView1'未映射。

After this it's not even possible to load the entities because all Mappings are lost. 此后,甚至不可能加载实体,因为所有映射都会丢失。
So how to design the views to be able to post updates using the Views AND to be able to update the edmx file? 那么,如何设计视图以能够使用视图发布更新并能够更新edmx文件?

MS is dropping support for EDMX files going forward in Entity Framework - in part due to the difficulty of keeping the database, EDMX, and POCOs all sync'd, as you are experiencing. MS放弃了对Entity Framework中对EDMX文件的支持-部分原因是,如您所经历的那样,很难使数据库,EDMX和POCO保持全部同步。 (Anyone can edit any of the 3, then changes are lost when a sync is done). (任何人都可以编辑3个中的任何一个,然后在同步完成后丢失更改)。

So they recommend using the Code First approach. 因此,他们建议使用“代码优先”方法。 Code First is a bit of a misnomer and causes some confusion. Code First有点用词不当,会引起一些混乱。

Code First doesn't mean you have to start with code. 代码优先并不意味着您必须从代码开始。
You can start with the database and then write your POCOs to match it (as in your case). 您可以从数据库开始,然后编写与之匹配的POCO(根据您的情况)。 Doing so allows you to preserve all your mappings and such because you just adjust your code to match the structure already present in your database. 这样做可以保留所有映射,这是因为您只需调整代码以匹配数据库中已经存在的结构。

Another misconception is that you have to use migrations . 另一个误解是您必须使用迁移 You do not. 你不。 You are welcome to not enable migrations and manually edit both the database schema and POCOs as long as you ensure they remain in sync. 欢迎您不要启用迁移并手动编辑数据库模式和POCO,只要您确保它们保持同步即可。

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

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