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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:09:02+00:00 2026-05-25T12:09:02+00:00

I have created a Stored Procedure that generates a GUID and then returns it

  • 0

I have created a Stored Procedure that generates a GUID and then returns it as a NVARCHAR, however when trying to access it using LINQ to SQL it is not being recognized as an ISingleResult. I have created numerous other procedures that have worked as expected such as:

CREATE PROCEDURE [dbo].[GetContact]
    @ContactID [int]
AS
BEGIN

    SET NOCOUNT ON;

SELECT
    ContactID,
    PrefixTypeID,
    FirstName,
    MiddleName,
    LastName,
    Suffix,
    LanguageTypeID,
    Organization,
    OrganizationLocation,
    OrganizationDepartmentTypeID,
    OrganizationEmployeeID,
    JobTitleID,
    TimeZone,
    AccountID,
    PortalID,
    CorporateAccountID,
    ContactRelationshipTypeID,
    EthnicityID,
    CitizenshipID,
    EducationID,
    ContactSalaryRangeID,
    Age,
    Birthday,
    IsMarried,
    LeadSourceTypeID
FROM Contact
WHERE ContactID = @ContactID 

END

using (Data.Contact.ContactDataContext contactDC = new Data.Contact.ContactDataContext())
{
    Data.Contact.GetContactResult contactResult = contactDC.GetContact(this.ID).SingleOrDefault();
}

However when I try to accomplish the same thing using the following Procedure I get the following error Cannot implicitly convert type 'System.Data.Linq.ISingleResult <OTS.Data.Application.GetSessionResult>' to 'OTS.Data.Application.GetSessionResult'. An explicit conversion exists (are you missing a cast?)

CREATE PROCECURE [dbo].[GetSession]

AS

    DECLARE @SessionID [nvarchar](38) = NEWID()

    INSERT INTO SessionTable (SessionID) VALUES (@SessionID)

    SELECT @SessionID As SessionID

When I run this in SSMS it returns the correct data, however in LINQ it does not. The other questions I’ve found similar to this one have either been unanswered or the answer was to not use LINQ. Is there a way to accomplish this using LINQ?

UPDATE


The code for GetSession is exactly the same as the GetContact. I have tried casting it but receive the error listed above.

The issue I’m experiencing is similar to this: Question about linq2sql

However we have tried removing and re-creating the dbml with no success…not only that but all new procedures that are created are now producing the same issue.

Using a UDF gives the output I need, however it does not work for my application. In my procedures I am checking for the existence of records before returning the data.

example

CREATE PROCEDURE [dbo].[GetPage]
    @PageName [nvarchar](255),
    @PagePath [nvarchar](255)
AS
BEGIN

    SET NOCOUNTON;

    DECLARE @PageID [int]

    IF NOT EXISTS(SELECT PageID FROM Page WHERE PagePath = @PagePath)
        BEGIN
            INSERT INTO Page(PageName, PagePath)
            VALUES(@PageName, @PagePath)

            SET @PageID = SCOPE_IDENTITY()
        END
    ELSE
        BEGIN
            SELECT @PageID = PageID
            FROM Page
            WHERE PagePath = @PagePath
        END

    --For the return values I have tried both ways below with the same results
    --ReQuery DB for data
    SELECT PageID, PageName, PagePath
    FROM Page
    WHERE PageID = @PageID

    --Query the Variables
    SELECT @PageID AS PageID, @PageName AS PageName, @PagePath AS PagePath

END

With the inability to do an INSERT or an EXEC inside of a UDF I cannot use them and need to use a SP. Any ideas are appreciated.

  • 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-25T12:09:03+00:00Added an answer on May 25, 2026 at 12:09 pm

    Oversight

    Make sure that you do not forget to include using System.Data.Linq as well as your data context.

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

Sidebar

Related Questions

I have just created a report in Report Manager using a Stored Procedure which
I have a stored procedure in SQL Server that returns some data via a
I'm using visual studio 2008 and I've created a stored procedure that selects back
I have a stored procedure that looks like: CREATE PROCEDURE dbo.usp_TestFilter @AdditionalFilter BIT =
Suppose I have a stored procedure that manages its own transaction CREATE PROCEDURE theProc
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have a dynamic SQL statement I've created in a stored procedure. I need
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I have a really simple stored procedure that looks like this: CREATE PROCEDURE _Visitor_GetVisitorIDByVisitorGUID
I have a stored procedure that accepts a date input that is later set

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.