简体   繁体   English

EF4和数据库视图

[英]EF4 and Database Views

Sorry this is quite a vague question. 抱歉,这是一个模糊的问题。 Been trying to find information on using a View with Entity Framework 4. Want to use it as a read only view, no interested in inserting/updating/deleting... Would just like to use a POCO with a view... 一直在尝试查找有关将视图与Entity Framework 4一起使用的信息。希望将其用作只读视图,对插入/更新/删除不感兴趣...仅想将POCO与视图一起使用...

[Update] [更新]

Thanks to the responders. 感谢响应者。 Zeeshan, actually reading your book currently. Zeeshan,实际上正在阅读您的书。

I can add a view via the "Update Model from Database" menu item and works great. 我可以通过“从数据库更新模型”菜单项添加视图,效果很好。 Just need to figure out how to setup the associations now... 现在只需要弄清楚如何设置关联...

You can add views to the Entity Designer the same way you do with tables, then treat the views as entities themselves. 您可以使用与表相同的方式向实体设计器中添加视图,然后将视图视为实体本身。 They're not treated exactly the same internally, and you may have to do some editing of the underlying XML. 它们在内部没有得到完全相同的处理,因此您可能必须对基础XML进行一些编辑。

Your question isn't clear on whether you're looking specifically for the difference between views in 3.5 and 4.0, but if you're looking for a general discussion of how views work in EF, this link has some information about it (based on 3.5): 您是否正在明确寻找3.5和4.0中视图之间的区别尚不清楚,但是如果您要对EF中视图的工作原理进行一般性讨论,则此链接包含有关它的一些信息(基于3.5):

Entity Framework: Creating a model using views instead of tables 实体框架:使用视图而不是表创建模型

Views are fully supported in RTM. RTM中完全支持视图。 One nice feature sneaked in very late in the product life cycle is, you can customize the key of the view from the conceptual model and it will sync it with the storage model as well. 在产品生命周期的最后阶段潜入的一项不错的功能是,您可以从概念模型中自定义视图的键,并且还将其与存储模型同步。 However there is still paint point with View where it needs to be mapped to an entity which must have a key. 但是,在View上仍然存在需要将其映射到必须具有键的实体的绘制点。 In future a view may be allowed to get mapped to a complex type. 将来可能会允许视图映射到复杂类型。 You can also use ExecuteStoreQuery for better performance. 您也可以使用ExecuteStoreQuery以获得更好的性能。

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

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