简体   繁体   中英

LINQ to SQL stored procedures with multiple results in Visual Studio 2008

I'm using visual studio 2008 and I've created a stored procedure that selects back two different result sets. I drag the stored proc on to a linq to sql dbml datacontext class, causing visual studio to create the following code in the cs file:

[Function(Name="dbo.List_MultiSelect")]
public ISingleResult<DataAccessLayer.DataEntities.List_MultiSelectResult> List_MultiSelect()
{
    IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
    return ((ISingleResult<DataAccessLayer.DataEntities.List_MultiSelectResult>)(result.ReturnValue));
}

Shouldn't the designer generate the code to use IMultipleResults? Or do I have to hand code that?

Using the designer will return an ISingleResult while using SqlMetal will generate the IMultipleResult that you expect. Otherwise, yes, you'll likely have to jump in there and tweak it directly.

An easy way would be to use SqlMetal then copy/paste the code it generates. Bear in mind that pasting it into the designer code might not be ideal since subsequent code generation will overwrite it. Perhaps you can move the relevant code to a partial class to avoid this issue.

My detailed answer here addresses this issue: SqlMetal wrongly generates the return type of my stored proc (LINQ)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM