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 3499302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:35:43+00:00 2026-05-18T12:35:43+00:00

Normally, when you want to call a stored procedure directly through Linq to Sql,

  • 0

Normally, when you want to call a stored procedure directly through Linq to Sql, you can use the ExecuteQuery method:

result = dc.ExecuteQuery<MyTable>("Exec myStoredProcedure");

And if you need to call it with parameters, you can add them through string substitution:

string query = "Exec myStoredProcedure ";
for (int i = 0; i < parameters.Count - 1; i++) {
  query += " {" + i + "},";
}
query = query.TrimEnd(',');
result = dc.ExecuteQuery<MyTable>(query, parameters);

But what if one of the parameters is an output variable? Is it possible to get the value back after the procedure has been run?

  • 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. Editorial Team
    Editorial Team
    2026-05-18T12:35:44+00:00Added an answer on May 18, 2026 at 12:35 pm

    Alper Ozcetin’s is right you can map StoredProcedures in *.dbml and you can use StoredProcedures as Method.

    Below is demo doing this with the AdventureWorks DB and works for both vs2008 and vs2010

    Wtih AdventureWorks I created the following Proc

    CREATE PROC sp_test (@City  Nvarchar(60) , @AddressID int out  )
    AS
    SELECT TOP 10 * FROM Person.Address where City = @City
    select  top 1  @AddressID  = AddressID FROM Person.Address where City = @City
    

    I then added sp_test to a dbml and wrote the following program

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Linq;
    
    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
    
    
                DataClasses1DataContext dc = new DataClasses1DataContext("SomeSQLConnection);
    
                int? AddressID = null;
                ISingleResult<sp_testResult> result = dc.sp_test("Seattle", ref AddressID);
    
                foreach (sp_testResult addr in result)
                {
                    Console.WriteLine("{0} : {1}", addr.AddressID, addr.AddressLine1);
                }
                Console.WriteLine(AddressID);
    
    
            }
        }
    }
    

    This results in the following ouput

    23 : 6657 Sand Pointe Lane
    91 : 7166 Brock Lane
    92 : 7126 Ending Ct.
    93 : 4598 Manila Avenue
    94 : 5666 Hazelnut Lane
    95 : 1220 Bradford Way
    96 : 5375 Clearland Circle
    97 : 2639 Anchor Court
    98 : 502 Alexander Pl.
    99 : 5802 Ampersand Drive
    13079
    

    You’ll notice that the input into the sp_test method is a ref

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

Sidebar

Related Questions

Normally, when I want to call a dynamic method in another ILGenerator object that
I want to call a method on an object which I get through [self
Here is what i want to do. Normally we can call javascript functions on
I want to detect when my touchpad is clicked! I normally use a usb
i know how to call prev/next normally but i want it to open the
I want to get a context-param configure in my web.xml. In a method call
I want to use jQuery to submit my form and i can do that
In case a system call function fails, we normally use perror to output the
If I want an empty enumeration, I can call Enumerable.Empty<T>() . But what if
I have a ridiculous question due to a ridiculous problem. Normally if I want

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.