execute custom sql with entity framework?

后端 未结 4 1347
半阙折子戏
半阙折子戏 2020-12-20 14:29

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 aut

4条回答
  •  情深已故
    2020-12-20 15:33

    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.

    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."

提交回复
热议问题