开发者

dbml generates ISingleResult<object> from my stored procedure when I want a collection

开发者 https://www.devze.com 2023-01-30 14:52 出处:网络
I\'ve created a stored procedure which I\'ve dragged on to my dbml file expecting it to create a method that will return a collection of objects. However it only gives me a method returning an ISingle

I've created a stored procedure which I've dragged on to my dbml file expecting it to create a method that will return a collection of objects. However it only gives me a method returning an ISingleResult.

My stored proc creates a table variable, populates it with data and then selects all from that table.

Any idea what I'm doing wrong? I can post code if that would be helpful.

Edit. Here's the generated code from the 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));
}

Here's a section of the stored procedure. It's pretty much this straightforward.

    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> inherits IEnumerable<T>. It is a collection.

It's a single result as opposed to a multiple result, as in multiple result sets:

SELECT *
FROM Table1

SELECT *
FROM Table2

A stored procedure like that would not return ISingleResult<T>.

0

精彩评论

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