Too much information!
Using *
within the SQL query has an unfortunate drawback. It retrieves everything based on the parameters passed into the query. This could mean hundreds of objects returned to List
.
As previously discussed, help is at hand. That help is in the form of LINQ.
Getting Linq'd
It should become apparent that LINQ is a powerful addition to the programmer's arsenal. To quote the grandfather of telesales, Billy Mays—but wait, there's more!
Finding data with LINQ
There are six ways of finding data within a collection:
Where
First
andFirstOrDefault
Single
andSingleOrDefault
Select
SelectMany
Last
andLastOrDefault
Where
Where
allows searching a collection based on any parameter within the collection. This will result in List<T>
or IEnumerable<T>
. If .ToList()
is omitted, IEnumerable
is generated:
var demoList = otherList.Where(t=>t.something == "foo"); var demoList = otherList.Where(t=>t.something == "foo").ToList();
First and FirstOrDefault
These two LINQ methods...