Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq-To-Sql SP won't map to class

Tags:

c#

linq-to-sql

I have a class in my Linq-To-Sql model and am trying to map a Stored Procedure to it. Whatever I try I get the message:

one or more selected database objects return a schema that does not match

The schema definitely does match, I have even resorted to just doing a auto generated 'select top 100 rows' in SSMS and putting this in the SP, nothing else, and I still get this message.

Is there anything else I should be looking at?

My table schema is as follows:

CREATE TABLE [dbo].[Booking](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [ClientID] [int] NULL,
    [BookingTypeID] [int] NULL,
    [LinkedBookingID] [int] NULL,
    [DateCreated] [smalldatetime] NULL,
    [DateUpdated] [smalldatetime] NULL,
    [BookingDateTime] [smalldatetime] NULL,
    [BookingStatusID] [int] NULL,
    [ConfirmationRequired] [bit] NOT NULL,
    [Confirmed] [bit] NOT NULL,
    [InProgress] [bit] NOT NULL,
    [ServiceID] [int] NULL,
    [EmployeeID] [int] NULL,
    [Duration] [int] NULL,
    [ProcessingDuration] [int] NULL,
    [IsPartOfCourse] [bit] NULL,
    [CancellationReason] [int] NULL,
    [Timestamp] [timestamp] NULL,
    [IsLinked] [bit] NULL,
 CONSTRAINT [PK_Booking] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

and SP:

CREATE PROCEDURE booking_test


AS
BEGIN


SELECT TOP 1000 [ID]
      ,[ClientID]
      ,[BookingTypeID]
      ,[LinkedBookingID]
      ,[DateCreated]
      ,[DateUpdated]
      ,[BookingDateTime]
      ,[BookingStatusID]
      ,[ConfirmationRequired]
      ,[Confirmed]
      ,[InProgress]
      ,[ServiceID]
      ,[EmployeeID]
      ,[Duration]
      ,[ProcessingDuration]
      ,[IsPartOfCourse]
      ,[CancellationReason]
      ,[Timestamp]

  FROM [Booking]

END
GO
like image 781
Macros Avatar asked Dec 07 '25 12:12

Macros


1 Answers

Add [IsLinked] to the queried columns in your stored procedure and it should work. (I just tested with your table, etc, and adding [IsLinked] to the stored procedure allowed me to drop the stored procedure onto the table in the designer without an error.)

I know that if you're using a stored procedure to query objects which are not LINQ to SQL entities (but you're using LINQ to SQL to auto-populate the objects), you can skip columns like you did with [IsLinked]. But if you're querying objects that are LINQ to SQL entities, you have to query all the columns. I think that's how it works.

like image 96
shaunmartin Avatar answered Dec 09 '25 02:12

shaunmartin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!