实体框架中的视图 [英] Views in entity framework

查看:73
本文介绍了实体框架中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
如何在实体框架中创建视图(ef)

hi how to create view in entity framework(ef)

推荐答案

您需要使用SQL查询创建视图。与EF一起使用的帖子。



参考:如何在实体框架中使用SQL Server视图 [ ^ ]
You need to create Views using SQL query. Post that use it with EF.

Refer: How to Use SQL Server Views with the Entity Framework[^]


你真的需要观点吗?使用 LINQ to Entities [ ^ ]您可以在实体集本身(另一侧的表)之上在托管代码中编写查询。只有在枚举时,查询才会转换为实际的sql查询语句(这称为延迟执行)。并且视图也在运行时进行评估(有一些预处理,但并不多) - 总的来说,你不会获得太多收益。因此,尽管您可以在EF模型中使用数据库侧视图(如Sandeep Mewara所指出的那样),但您必须考虑是否确实需要它们。

这样想:在传统开发中,很多业务逻辑都放在dbms端(视图和存储过程一般都是这样的),所以BL分为两个或更多轮胎。 EF的理念是将数据库视为一个简单的数据存储区,并且正在推动开发人员在数据访问层之上构建BL(考虑到应用程序级实体) - 而不是拆分甚至低于DAL。
Do you really need views? With LINQ to Entities[^] you can write queries in managed code on top of the entity sets themselves (tables on the other side). The query will be transformed to actual sql query statements only when it is enumerated (this is called deferred execution). And as views are evaluated at runtime too (there is a little preprocessing, but not much) - in general you won''t gain a lot. So, although you can use the database side views in your EF model (as Sandeep Mewara pointed out), you have to consider if you really need them.
Think like this: in the traditional development, the lot of the business logic is put on dbms side (views and stored procedures are in general such things), so the BL is split between two or more tires. The EF philosophy is treating the database more like a simple datastore, and is pushing the developer to forge the BL above the data access layer (with the application level entities in mind) - and not split or even below DAL.


这篇关于实体框架中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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