Peter Jones
Peter Jones

Reputation: 55

Select few columns in Entity Framework

I am new to entity framework. My table is having more than 20 columns. But sometimes, I need only 2-3 columns from it. Is it a good practice to bring entire rows as Model class object or just use a LINQ to Entity query? Can you please give occasions to choose the best method?

Thanks Peter

Upvotes: 0

Views: 74

Answers (1)

Steve Py
Steve Py

Reputation: 34988

Just return what you need using a .Select() operation. This can significantly improve performance by making the query quicker and reducing the amount of data coming across the wire from the database server.

Upvotes: 1

Related Questions