markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

Getting "Incorrect syntax near 'dbo'" error trying to use .skip and .take with multiple primary keys #264

Closed thumbs90 closed 11 years ago

thumbs90 commented 11 years ago

I am trying to implement paging on one of my DB tables using .Skip() and .Take().

Here's my code snippet: public IEnumerable FetchAll(int startIndex, int pageSize) { return Database.OpenConnection(m_ConnectionString)["Account"].All().Skip(startIndex).Take(startIndex).Cast(); }

and am getting the following error: {"Incorrect syntax near 'dbo'."}

The command that is generated by Simple.data is: WITH __Data AS (SELECT [dbo].[Account].[AccountID],[dbo].[Account].[InstanceName], ROWNUMBER() OVER(ORDER BY [dbo].[Account].[AccountID], [dbo].[Account].[InstanceName]) AS [#_] from [dbo].[Account]) SELECT [dbo].[Account].[ID],[dbo].[Account].[AccountID],[dbo].[Account].[InstanceName],[dbo].[Account].[UserGroup],[dbo].[Account].[Enable],[dbo].[Account].[ChangePassword],[dbo].[Account].[ReadOnly],[dbo].[Account].[PasswordPhone],[dbo].[Account].[Name],[dbo].[Account].[Country],[dbo].[Account].[City],[dbo].[Account].[State],[dbo].[Account].[Zip],[dbo].[Account].[Address],[dbo].[Account].[Phone],[dbo].[Account].[Email],[dbo].[Account].[Comment],[dbo].[Account].[IRD],[dbo].[Account].[Status],[dbo].[Account].[RegistrationDate],[dbo].[Account].[LastDate],[dbo].[Account].[Leverage],[dbo].[Account].[AgentAccount],[dbo].[Account].[Balance],[dbo].[Account].[PreviousMonthBalance],[dbo].[Account].[PreviousBalance],[dbo].[Account].[Credit],[dbo].[Account].[InterestRate],[dbo].[Account].[Taxes],[dbo].[Account].[PreviousMonthEquity],[dbo].[Account].[PreviousEquity],[dbo].[Account].[SendReports],[dbo].[Account].[UserColor],[dbo].[Account].[Equity],[dbo].[Account].[Margin],[dbo].[Account].[MarginLevel],[dbo].[Account].[MarginFree],[dbo].[Account].[ModifyTime] FROM Data JOIN [dbo].[Account] ON [dbo].[Account].[AccountID] = Data.[AccountID] [dbo].[Account].[InstanceName] = _Data.[InstanceName] AND [#_] BETWEEN 3 AND 4

My DB table has 2 primary keys AccountID (bigint) and InstanceName (nvarchar(64).

Works fine with DB tables with a single primary key, but errors out on multiples.