如何从BLL返回多表连接值
这个问题是关于我正在为我的最终学校项目使用 DAL-BLL 架构创建的 ASP.NET Web 服务。
我有一个存储过程,它是一个带有 2 个表的内部联接的选择查询。因此,存储过程返回多表值。我的 DAL tableAdapter 方法之一访问此存储过程。如何检索 BLL 中的返回值?我是否必须创建一个类似于存储过程返回的类结构?或者有没有直接的方法可以达到同样的目的?非常感谢帮助。如果有人需要代码小程序来更好地理解,请告诉我。谢谢
这里有一些更多信息: 我在 DAL 中使用 SQL 数据集 (.xsd)。所以我有一个名为“保险”的数据表,其中有一个表适配器。适配器中的查询之一引用了具有内部联接的存储过程。所以我的 SP 看起来像:
ALTER PROCEDURE dbo.GetInsurancesPaged
(
@startRowIndex int,
@maximumRows int,
@patientID int
)
AS
select * from
(
SELECT Insurance.insuranceID, Insurance.memberID, Insurance.groupID, Insurance.accountType, Insurance.comments, Insurance.patient, Insurance.company, InsuranceCompany.companyID, InsuranceCompany.companyName, InsuranceCompany.address, InsuranceCompany.phone, InsuranceCompany.fax, ROW_NUMBER() over (order by Insurance.dateModified DESC) as ROWRANK
FROM Insurance INNER JOIN InsuranceCompany ON Insurance.company = InsuranceCompany.companyID
WHERE Insurance.patient = @patientID
)
AS DataWithRowNumbers
WHERE ROWRANK > @startRowIndex AND ROWRANK <= (@startRowIndex + @maximumRows)
所以这个 SP 返回一个数据表,它将是内连接中 2 个表的组合。如果我错了,请纠正我。
现在在我的 BLL 中,我有:
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
public mySys.InsuranceDataTable GetInsurancesPaged(int startRowIndex, int maximumRows, int patientID)
{
return insAdapter.GetInsurancesPaged(startRowIndex, maximumRows, patientID);
}
其中 insAdapter 是 InsuranceTableAdapter 的一个实例
这会在执行时出现错误。我可以成功执行 SP,所以我认为问题只是 bcz 我试图从 BLL 返回错误的数据表。 请帮我解决这个问题。
This question is regarding the ASP.NET webservice that i am creating using the DAL-BLL architecture for my final school project.
I have a stored procedure, which is a select query with an inner join for 2 tables. Hence the stored procedure returns multi-table value. One of my DAL tableAdapter methods accesses this stored procedure. How do i retrieve the return value in the BLL? Do i have to create a class structure similar to the one supposed to be returned by the stored proc? or is there a direct way to achieve the same? Help greatly appreciated. Please let me know if someone needs code applet to get a better understanding. Thanks
Here is some more information:
I am using the SQL dataset (.xsd) in DAL. So i have a datatable called "Insurance", which has a tableAdapter. One of the queries in the adapter references to a stored procedure, which has an inner join. So my SP looks like:
ALTER PROCEDURE dbo.GetInsurancesPaged
(
@startRowIndex int,
@maximumRows int,
@patientID int
)
AS
select * from
(
SELECT Insurance.insuranceID, Insurance.memberID, Insurance.groupID, Insurance.accountType, Insurance.comments, Insurance.patient, Insurance.company, InsuranceCompany.companyID, InsuranceCompany.companyName, InsuranceCompany.address, InsuranceCompany.phone, InsuranceCompany.fax, ROW_NUMBER() over (order by Insurance.dateModified DESC) as ROWRANK
FROM Insurance INNER JOIN InsuranceCompany ON Insurance.company = InsuranceCompany.companyID
WHERE Insurance.patient = @patientID
)
AS DataWithRowNumbers
WHERE ROWRANK > @startRowIndex AND ROWRANK <= (@startRowIndex + @maximumRows)
So this SP returns a datatable which will be a combination of the 2 tables in the inner join. Please correct me if i am wrong.
Now in my BLL, i have:
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
public mySys.InsuranceDataTable GetInsurancesPaged(int startRowIndex, int maximumRows, int patientID)
{
return insAdapter.GetInsurancesPaged(startRowIndex, maximumRows, patientID);
}
where insAdapter is an instance of insuranceTableAdapter
This gives an error on execution. I can execute the SP successfully, so i think the problem is only bcz i am trying to return a wrong datatable from the BLL.
Please help me solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用 ADO .Net 数据集。向导将明确地为其创建一个表。现在从数据访问层执行以下步骤
If using ADO .Net dataset. The wizard will definetly create a table for the same. now from the dataaccess layer, do the following steps
找到了解决方案:)
终于成功了。
我使用数据集设计器创建了一个新的表适配器,并将 SP 称为其中的查询之一。由此创建的数据表包含所有字段(来自 Insurance 和 InsuranceCompany)。现在,ASP.NET 可以检测到返回类型是新创建的数据表。
就像魅力一样。
如果有更好的方法来解决这个问题,欢迎评论。
感谢大家抽出宝贵的时间。
Found a solution :)
Finally got it working.
I created a new table adapter using the Dataset designer, and called the SP as one of the queries there. The datatable thus created, has all the fields (from Insurance and InsuranceCompany) included. Now, ASP.NET can detect that the return type is the newly created datatable.
Works like a charm.
If there is a better way to solve this, please comment.
Thank you all for your time.