Skip to main content
 首页 » 编程设计

c#之当我想要一个集合时,dbml 从我的存储过程中生成 ISingleResultobject>

2024年02月03日34虾米哥

我创建了一个存储过程,并将其拖到我的 dbml 文件中,希望它创建一个返回对象集合的方法。但是它只给了我一个返回 ISingleResult 的方法。

我的存储过程创建一个表变量,用数据填充它,然后从该表中选择所有内容。

知道我做错了什么吗?如果有帮助,我可以发布代码。

编辑。这是从 dbml 生成的代码

[Function(Name="dbo.gr_RecentActions")] 
public ISingleResult<Action> gr_RecentActions([Parameter(Name="UserID", DbType="UniqueIdentifier")] System.Nullable<System.Guid> userID) 
{ 
    IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), userID); 
    return ((ISingleResult<Action>)(result.ReturnValue)); 
} 

这是存储过程的一部分。就这么简单。

    ALTER PROCEDURE [dbo].[gr_RecentActions] 
@UserID UNIQUEIDENTIFIER 
AS 
BEGIN 
 
DECLARE @RecentActions AS TABLE (UserId UNIQUEIDENTIFIER, UserID1 UNIQUEIDENTIFIER, Name VARCHAR(500), GiftID UNIQUEIDENTIFIER, ActionType VARCHAR(20), ActionDate DATETIME) 
 
DECLARE @Friends AS Table (Userid UNIQUEIDENTIFIER) 
 
INSERT INTO @Friends (Userid) 
    (SUBQUERY...) 
 
 
 
INSERT INTO @RecentActions (UserId, UserId1, Name, GiftID, ActionType, ActionDate) 
    SELECT userid, NULL, Name, g.GiftId, 'GiftAdded', DateCreated FROM Gift g  
    WHERE UserId IN  
        (select UserId from @Friends) 
 
/* SNIP.... SIMILAR CODE TO ABOVE */ 
 
 
SELECT * FROM @RecentActions ORDER BY ActionDate DESC 

请您参考如下方法:

ISingleResult<T>继承IEnumerable<T> .它是一个集合。

它是单个结果,而不是多个结果,如在多个结果集中:

SELECT * 
FROM Table1 
 
SELECT * 
FROM Table2 

像这样的存储过程不会返回 ISingleResult<T> .