问题描述
我需要执行它西港岛线在数据库中的某处保存一个customquery,我需要它返回的数据表或数据集并将其绑定到一个gridview这将有自动生成列设置为true。
I need to execute a customquery which wil be saved somewhere in the database and I need it to return in a datatable, or dataset and bind it to a gridview which will have autogenerate columns to true.
我所有的数据访问层,可以完美兼容实体框架,但对一些特定情况下,我需要做到这一点,我不知道是否要结合ado.net实体框架,或EF能以某种方式做到这一点
All my Data access layer works perfect with entity framework, but for some specific scenario I need to do this and I wonder if I should combine ado.net with entity framework, or if EF can do it somehow
推荐答案
如果你的目标是返回ADO.NET结构(数据表或数据集),那么就用经典的ADO.NET。你会发现不是试图将数据绑定到一个实体集合,然后填充一个DataTable或数据集自己更容易。
If your goal is to return ADO.NET structures (DataTable or DataSet), then just use classic ADO.NET. You'll find it easier than trying to bind data to an Entity set and then populating a DataTable or DataSet yourself.
但是,如果你真的和真正感兴趣的贯穿的EntityFramework自定义查询,看看的executeQuery 。它可以让你执行一个SQL查询和地图的结果返回给模型中的实体。那么这将是一个锻炼对你的一部分采取了IEnumerable结果,并将其映射到一个数据表或数据集。因此,我原来的只管去做具有良好的醇'老式ADO.NET的方法。答案
However, if you're really and truly interested running a custom query through EntityFramework, take a look at ExecuteQuery. It allows you to execute a SQL Query and maps the result back to entities in your model. It would then be an exercise on your part to take the IEnumerable result and map it to a DataTable or DataSet. Hence my original answer of "just do it with good ol' fashioned ADO.NET methods."
这篇关于与实体框架执行自定义的SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!