code_junkie

LINQ-to-SQL: Stored Procedure that returns a single scalar value?

Nov 12th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. private ISingleResult<sp_xal_seqnoResult> NextRowNumber([Parameter(DbType="Int")] System.Nullable<int> increment, [Parameter(DbType="Char(3)")] string dataset)
  2.  
  3. <Function Name="dbo.foo" Method="foo">
  4. <Parameter Name="inc" Type="System.Int32" DbType="Int" />
  5. <Parameter Name="dataset" Type="System.String" DbType="VarChar(20)" />
  6. <Return Type="System.Int32" />
  7. </Function>
  8.  
  9. [Function(Name="dbo.foo")]
  10. public int foo([Parameter(DbType="Int")] System.Nullable<int> inc, [Parameter(DbType="VarChar(20)")] string dataset)
  11. {
  12. IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), inc, dataset);
  13. return ((int)(result.ReturnValue));
  14. }
  15.  
  16. <Function Name="dbo.foo" Method="FooPrivate" AccessModifier="Private">
  17. <Parameter Name="inc" Type="System.Int32" DbType="Int" />
  18. <Parameter Name="dataset" Type="System.String" DbType="VarChar(20)" />
  19. <ElementType Name="fooResult" AccessModifier="Internal">
  20. <Column Name="value" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
  21. </ElementType>
  22. </Function>
  23.  
  24. [Function(Name="dbo.foo")]
  25. private ISingleResult<fooResult> FooPrivate(
  26. [Parameter(DbType="Int")] System.Nullable<int> inc,
  27. [Parameter(DbType="VarChar(20)")] string dataset)
  28. {
  29. IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), inc, dataset);
  30. return ((ISingleResult<fooResult>)(result.ReturnValue));
  31. }
  32.  
  33. namespace MyNamespace {
  34. partial class MyDataContext
  35. {
  36. public int Foo(int? inc, string dataSet)
  37. {
  38. return FooPrivate(inc, dataSet).Single().value;
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment