如何使用实体框架存储过程获取多个查询数据。 [英] how to get multiple queries data using entity framework stored procedure.

查看:107
本文介绍了如何使用实体框架存储过程获取多个查询数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是我的代码:

这是我的程序

 ALTER proc [dbo]。[GetTotalDataByIp] 
@cntid int,
@checkid int
as
begin
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
设置NOCOUNT ON;
If(@checkid = 1)
begin

SELECT top(24)LocationName,
COUNT(LocationName)AS TotalCount
FROM
Job WITH(NOLOCK)其中CountryId = @cntid和LocationName!=''和LocationName!='???'
GROUP BY LocationName ORDER BY TotalCount DESC

end
else if(@checkid = 2)
begin
SELECT top(16)CompanyName,
COUNT(CompanyName)AS TotalCount
FROM
Job WITH(NOLOCK)其中CountryId = @cntid和CompanyName!=''和isactive = 1
GROUP BY CompanyName ORDER BY TotalCount DESC
end
end





我必须作为复杂类型导入,但只有当条件字段只显示Locationname和Totalcout时才会导入。



在我的页面加载中我绑定了这...



  int  getcountry =  108 ; 
var getlocationbyip = dc.GetTotalDataByIp(getcountry, 1 );
if (getlocationbyip!= null
{
rptgetlocations。 DataSource = getlocationbyip;
rptgetlocations.DataBind();
}

// var getcompaniesbyip = dc.getcompaniesbyip(getcountry);
var getcompaniesbyip = dc.GetTotalDataByIp(getcountry, 2 );

if (getcompaniesbyip!= null
{
rptcompanies.DataSource = getcompaniesbyip;
rptcompanies.DataBind();
}



第二次转发器绑定时出错。

请帮帮我..

谢谢你...

解决方案

看看这篇文章,对同一事件给予了很好的评价

从具有功能导入映射的实体框架存储过程返回多个结果集 [ ^

Hi,

This is my code:
This is my Procedure

ALTER proc [dbo].[GetTotalDataByIp]
@cntid int,
@checkid int
as
begin
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON;
If(@checkid = 1)
begin

SELECT top(24) LocationName,
COUNT(LocationName) AS TotalCount
FROM
Job WITH (NOLOCK) where CountryId = @cntid and LocationName !=' ' and LocationName !='???'
GROUP BY LocationName ORDER BY TotalCount DESC

end
else if(@checkid = 2)
begin
SELECT top(16) CompanyName,
COUNT(CompanyName) AS TotalCount
FROM
Job WITH (NOLOCK) where CountryId = @cntid and CompanyName != ' ' and isactive=1
GROUP BY CompanyName ORDER BY TotalCount DESC
end
end



I have to import as complex type but only first if condition fields shows only like Locationname and Totalcout.

In my page load I have bind like this...

int getcountry=108;
var getlocationbyip = dc.GetTotalDataByIp(getcountry, 1);
            if (getlocationbyip != null)
            {
                rptgetlocations.DataSource = getlocationbyip;
                rptgetlocations.DataBind();
            }

            //var getcompaniesbyip = dc.getcompaniesbyip(getcountry);
            var getcompaniesbyip = dc.GetTotalDataByIp(getcountry, 2);

            if (getcompaniesbyip != null)
            {
                rptcompanies.DataSource = getcompaniesbyip;
                rptcompanies.DataBind();
            }


I got error when second repeater binding.
Please help me..
Thank you...

解决方案

have a look at this article, it has been given great reviews on the same matter
Returning Multiple Result Sets from an Entity Framework Stored Procedure with Function Import Mappings[^]


这篇关于如何使用实体框架存储过程获取多个查询数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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