For better understanding please go through the following
The following tsql code shows how the spoc which returns multiple result sets look like
CREATE PROCEDURE GetMultipleResults
@SomeID int
AS
BEGIN
SELECT * FROM SomeTable1 where SomeColumn1=@SomeID
SELECT * FROM SomeTable2 where SomeColumn2=@SomeID
SELECT * FROM SomeTable3 where SomeColumn3=@SomeID
SELECT * FROM SomeTable4 where SomeColumn4=@SomeID
END
The below code shows how to get the IMultipleResult object by calling the above sproc using LINQ
[Function(Name = "dbo.SPROCName")]
[ResultType(typeof(ResultSet1))]
[ResultType(typeof(ResultSet2))]
[ResultType(typeof(ResultSet3))]
[ResultType(typeof(ResultSet4))]
public IMultipleResults SomeMethod([Parameter(DbType = "INT")] int? SomeID
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), SomeID);
return ((IMultipleResults)(result.ReturnValue));
}
The below code shows how to read the result set from the object of IMultipleResult type
public void SomeOtherMethod(int SomeID)
{
DataContext1 context = new DataContext1 (dbConnString);
IMultipleResults results = context.SomeMethod(SomeID);
ResultSet1 resultSet1= results.GetResult
IEnumerable
IEnumerable
ResultSet4 resultSet4= results.GetResult
}
If you observe the above code you can notice that the method is reading individual result sets from the IMultipleResult object in the same sequence as the sproc returns the results. This is very important that the order of the IMultipleResults.GetResult() statements for the result sets should be same as the order of the select statements in sproc. If the order is different then you will get runtime errors or invalid objects and many more issues.
2 comments:
u r telling for select statements which are retrieving result from one table..
i want for join condition..
please help me..
The problem with this elementary oft repeated explanation is you're creating a new connection to the database with the DataContext object... what good then is linq or entity? I may as well use ADO.Net and skip the middle man... this as with all of the other SAME explanation is such a waste of my time, I may has well just using ADO.NET
Post a Comment