Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select vs Select new in linq

Tags:

linq

What's the difference b/w select and select new in linq.

var SelectNew = from L1 in liStudent select new { L1.Name, L1.ID };

var SelectNew2 = from L2 in liStudent select L2;
like image 870
Mohan Sharma Avatar asked Dec 25 '10 09:12

Mohan Sharma


1 Answers

Your first one, SelectNew is returning an enumerable of anonymous types with two properties, Name and ID, whereas SelectNew2 is returning an enumerable of iiStudent entities. You'd use the first instance when you need to return a subset of the data available in the entity/model.

like image 58
Matthew Abbott Avatar answered Nov 05 '22 12:11

Matthew Abbott