DannyD
DannyD

Reputation: 2881

how can I return a certain amount of items from my db using linq statements in c#

I have a call to my database in my c# code that looks like this:

var filter = new PrioritizeSessionFilter()
            .Add(DbTable.PrioritizeSession.Columns.IsArchived, Comp.Equals, false);

var list = UnitOfWork.PrioritizeSessions.Query(filter);

Is there a way I can only return 10 items at a time instead of all of them at once? Is there a filter I could possibly create to do this?

Upvotes: 1

Views: 115

Answers (2)

David L
David L

Reputation: 33823

While walkhard is correct, you should generally use skip when using take so that if you need a different ten items, you can return those as well

 var amyList = UnitOfWork.PrioritizeSessions.Query(filter).Skip(skip).Take(10).ToList();

Upvotes: 1

Zbigniew
Zbigniew

Reputation: 27594

You can use Take extension method:

// get 10 elements
var myList = UnitOfWork.PrioritizeSessions.Query(filter).Take(10);

Upvotes: 7

Related Questions