Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 89219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:40:56+00:00 2026-05-10T22:40:56+00:00

I am using LINQ-to-SQL for an application that queries a legacy database. I need

  • 0

I am using LINQ-to-SQL for an application that queries a legacy database. I need to call a stored procedure, that selects a single integer value. Changing the stored procedure is not an option.

The designer creates a method with this signature:

private ISingleResult<sp_xal_seqnoResult> NextRowNumber([Parameter(DbType='Int')] System.Nullable<int> increment, [Parameter(DbType='Char(3)')] string dataset) 

I would like the return type to be int. How do I do this using LINQ-to-SQL ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:40:57+00:00Added an answer on May 10, 2026 at 10:40 pm

    This would be trivial with a scalar function (UDF) rather than an SP. However, it should work easily enough – although if the SP is complex (i.e. FMT_ONLY can’t inspect it 100%) then you might need to ‘help’ it…

    Here’s some dbml that I generated from a simplfied SP that returns an integer; you can edit the dbml via ‘open with… xml editor):

    <Function Name='dbo.foo' Method='foo'>     <Parameter Name='inc' Type='System.Int32' DbType='Int' />     <Parameter Name='dataset' Type='System.String' DbType='VarChar(20)' />     <Return Type='System.Int32' /> </Function> 

    (note you obviously need to tweak the names and data-types).

    And here is the generated C#:

    [Function(Name='dbo.foo')] public int foo([Parameter(DbType='Int')] System.Nullable<int> inc, [Parameter(DbType='VarChar(20)')] string dataset) {     IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), inc, dataset);     return ((int)(result.ReturnValue)); } 

    If your current SP uses SELECT (instead of RETURN), then the DBML will need to reflect this. You can fix this by hiding the implementation details, and providing a public wrapper in a partial class; for example:

    <Function Name='dbo.foo' Method='FooPrivate' AccessModifier='Private'>     <Parameter Name='inc' Type='System.Int32' DbType='Int' />     <Parameter Name='dataset' Type='System.String' DbType='VarChar(20)' />     <ElementType Name='fooResult' AccessModifier='Internal'>       <Column Name='value' Type='System.Int32' DbType='Int NOT NULL' CanBeNull='false' />     </ElementType> </Function> 

    The above describes an SP that returns a single table with a single column; but I’ve made the SP ‘private’ to the data-context, and the result-type ‘internal’ to the assembly (hiding it):

    [Function(Name='dbo.foo')] private ISingleResult<fooResult> FooPrivate(     [Parameter(DbType='Int')] System.Nullable<int> inc,     [Parameter(DbType='VarChar(20)')] string dataset) {     IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), inc, dataset);     return ((ISingleResult<fooResult>)(result.ReturnValue)); } 

    Now in my own class file I can add a new partial class (a new .cs file) in the correct namespace, that exposes the method more conveniently:

    namespace MyNamespace {     partial class MyDataContext     {         public int Foo(int? inc, string dataSet)         {             return FooPrivate(inc, dataSet).Single().value;         }     } } 

    (the namespace and context names need to be the same as the actual data-context). This adds a public method that hides the grungy details from the caller.

    Don’t edit the designer.cs file directly; your changes will be lost. Only edit either the dbml or partial classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $("#range123").click(function() { var from = $("#frm_range").val(); var to = $("#to_range").val();… May 11, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer Make sure that you hook on application exit event a… May 11, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer Same :) you send JSON array (comming from the form)… May 11, 2026 at 10:22 pm

Related Questions

I am looking for a more sophisticated way of using Linq to SQL. I
I am using asp.net mvc for an application. I've taken some guidance from Rob
What is the best way to check for concurrency issues when using LINQ to
I am working on a winforms application using LINQ to SQL - and am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.