如何在EDMX文件中使用动态查询,即企业库 [英] How to we use dynamic queries in EDMX files i.e. Enterprise library

查看:69
本文介绍了如何在EDMX文件中使用动态查询,即企业库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我无法控制数据库,因为它是由客户端管理的。我们应该创建UI来显示来自DB的值。在某些存储过程中,用户通过动态SQL查询返回数据。现在我们发现在Entity Framework中为这些proc创建edmx对象存在问题。伙计们请在这里帮忙。



技术:ASP.Net MVC,实体框架5,MS-SQL服务器



我尝试了什么:



我们尝试使用ADO.Net,但我们希望通过企业库调用它。它肯定会被微软处理。

In my one of the project I am not having control over database because it is managed by client. We are supposed to create UI to show values from DB. In some stored procedures user is returning data through Dynamic SQL Query. Now we are finding issue in creating edmx objects in Entity Framework for these procs. Guys please help here.

Technology : ASP.Net MVC, Entity Framework 5, MS-SQL Server

What I have tried:

We tried using ADO.Net but we want to call the same through enterprise library. It would be definitely handled by Microsoft.

推荐答案

好像你想建立一个 IQueryable< T> 。在EF上搜索动态查询表达式以获取更多信息。以下是可以帮助您入门的一个示例:带有实体的动态查询表达式框架|带风的代码 [ ^ ]



如果您期望得到一组不同的结果,那么您可以使用 IEnumerable< dynamic> 返回基于行sql动态查询的匿名对象。



此外,如果你想利用EF的新功能,包括完整支持storedprocedures然后你想要看看EF 6:实体框架代码第一个和存储过程 [ ^ ]
Seems like you would want to build an IQueryable<T>. Search on Dynamic Query Expression on EF to get more information. Here's one example that may help you get started: Dynamic Query Expressions With Entity Framework | Code with the wind[^]

If you are expecting a different set of results then you can use IEnumerable<dynamic> to return anonymous object based from row sql dynamic query.

Also, if you want to take advantage of the new features of EF including full support of storedprocedures then you want to look at EF 6 instead: Entity Framework Code First and Stored Procedures[^]


最简单的方法 - 设置自己的数据库,将数据导入其中(使用客户的存储过程获取数据),然后编写EF模型从您的数据库加载它。



EF将无法正确定义从临时表中选择的存储过程*返回的数据集*中的模型,或者(看来)动态sql。如果您使用的是EF6或更早版本,请不要屏住呼吸等待MS修复。他们根本不想维护比EF7(.Net Core)更旧的东西。
The easiest way - setup your own database, import the data into it (using the customer's stored procedures to acquire the data), and then write EF models to load it from YOUR database.

EF will NOT be able to properly define models from datasets *returned by stored procs* that are selected from temp tables, or (it appears) dynamic sql. If you're using EF6 or earlier, don't hold your breath waiting for a fix from MS. They're not at all interested in maintaining anything older than EF7 (.Net Core).


这篇关于如何在EDMX文件中使用动态查询,即企业库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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