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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:35:22+00:00 2026-05-17T14:35:22+00:00

Am trying to get linq to call a stored procedure. I know this is

  • 0

Am trying to get linq to call a stored procedure. I know this is usually rather simple, but in this case i am using my own Custom Entity Classes and I am at a dead end.

the link below will show you how I have my OM setup

example

does any one know how you can call a stored procedure from your own Custom Entity Class?

EDIT:

Forgot two things.

1) this will be a silverlight app
2) I have tired This on MSDN but I get cannot call a security function execption.

  • 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-17T14:35:23+00:00Added an answer on May 17, 2026 at 2:35 pm

    Your question is a little vague so I’m not sure if this will help, but I just ran a little test using the AdventureWorks db and it seemed to work – I’ll post my test code and maybe it’ll give you a clue. (This is just fetching 3 columns from the Employee table into a new/custom “EmpTest” class.)

    The stored procedure:

    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Get_Employee]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[Get_Employee]
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE PROCEDURE Get_Employee 
        @id int = 0
    AS
    BEGIN
        SET NOCOUNT ON;
    
        SELECT EmployeeID, Title, VacationHours from HumanResources.Employee where EmployeeID = @id
    END
    GO
    

    The LINQ to SQL stored procedure method (put this in your DataContext class):

    [Function(Name="dbo.Get_Employee")]
    public ISingleResult<EmpTest> Get_Employee([Parameter(DbType="Int")] System.Nullable<int> id)
    {
        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), id);
        return ((ISingleResult<EmpTest>)(result.ReturnValue));
    }
    

    The custom entity:

    [Table(Name = "HumanResources.Employee")]
    public class EmpTest
    {
        private int _EmployeeID;
        private string _Title;
        private short _VacationHours;
    
        [Column(Storage = "_EmployeeID", DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int EmployeeID
        {
            get { return this._EmployeeID; }
            set { this._EmployeeID = value; }
        }
    
        [Column(Storage = "_Title", DbType = "NVarChar(50) NOT NULL", CanBeNull = false)]
        public string Title
        {
            get { return this._Title; }
            set { this._Title = value; }
        }
    
        [Column(Storage = "_VacationHours", DbType = "SmallInt NOT NULL")]
        public short VacationHours
        {
            get { return this._VacationHours; }
            set { this._VacationHours = value; }
        }
    }
    

    And, finally the call:

    EmpTest emp = context.Get_Employee(41).SingleOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert a record into a table using Linq but get
I am using Linq to SQL to call a stored procedure which runs a
Ok, I'm trying to get this working. This is my first time using LINQ.
I'm trying to do a simple call to a database stored procedure from a
I am trying to get my linq query to replicate my t-sql but I
I am trying to get decimal value using LINQ in a MVC3 project. How
I'm trying to get this sitemap clas s working. It appears to use LINQ,
I am using Entity Framework. I am trying to get the results from linq
Trying to write dynamic queries using the LINQ provider for NHibernate, but I am
Sorry for this simple question . I have a Stored Procedure that return an

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.