开发者

calling stored procedure from linq

开发者 https://www.devze.com 2023-03-03 20:14 出处:网络
hey guys, i have a stored procedure known as sp_sitesearch, which returns the result of the site search, now what i want to do is, i want to call this sp to gridview using LINQ, coz one of my friend s

hey guys, i have a stored procedure known as sp_sitesearch, which returns the result of the site search, now what i want to do is, i want to call this sp to gridview using LINQ, coz one of my friend suggested that linq's开发者_运维知识库 performance is faster than DataTable or DataSet. so i want to try that, so i created a dbml, and added my SP inside this, and inside the .cs i wrote below code.

SiteSearchDataContext siteSearch = new SiteSearchDataContext(); gridArticle.DataSource = siteSearch.sp_SiteSearch(1, keyword); gridArticle.DataBind();

here it throws an error saying, it should return IEnumerable or IDataSource, i got a shock when i found that it returns int... but i dont know how, as my sp is not returning anything, it just returns a resultset, so can anyone suggest me how should i use this to bind gridview.


It sounds like you didn't map your stored procedure to have a return type in your entity data model. If you go back into your data model and edit your Function Import, there should be a section of the window labeled "Returns a Collection Of" that you can use to define what your stored proc is returning. Hopefully what it's returning can be mapped directly to an entity type in your data model, as that will allow you to simply pick an entity from the dropdown. If your results are returned in a way that doesn't map cleanly to an existing entity, refer to How to: Map a Function Import to a Complex Type (Entity Data Model Tools) on MSDN.


You can't bind an IQueryable to a DataSource. You need

gridArticle.DataSource = siteSearch.sp_SiteSearch(1, keyword).ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消