I have two tables:
Topic ( TopicID: int, (primary key) TopicName: varchar ); Example ( ExampleID: int, (primary key) TopicID: int, (foreign key to Topic table) ExampleOrder: int, ExampleName: varchar );
Using Linq, given an ExampleID, I want to get the next example in the same topic (with the same TopicID). Here’s how it might be done in sql:
DECLARE @ExampleOrder int; DECLARE @TopicID int; SELECT @ExampleOrder=ExampleOrder, @TopicID=TopicID FROM Example WHERE ExampleID=@ExampleID; SELECT TOP 1 ExampleID FROM Example WHERE TopicID=@TopicID AND ExampleOrder>@ExampleOrder ORDER BY ExampleOrder
Is there a simple way to do this in Linq? I know I can do this with two Linq queries, but I’m trying to get it done without extra round trips to the database.
1 Answer