Prev | Current Page 169 | Next

Satheesh, N Kumar

"LINQ Quickly"

By
setting the property to True, the field data will be loaded with a delay.
Chapter 4
[ 105 ]
Projections
All the queries that we have seen previously are for entity objects, for fetching
records from the database tables. There are situations where we may not require
all columns of the tables. We might require only two or three columns out of many
columns in the tables. LINQ to SQL query supports this feature for getting values of
only one or more columns.
For example, we might want to know the name of the ice-creams and their
ingredients. We may not be interested in any other details about the ice-creams. So,
the query will look like this:
var projItems = from itms in db.Items
where itms.CategoryID == 1
select new {itms.Name, itms.Ingredients};
The equivalent query expression that is assigned to the variable would be like this:
LINQ to SQL
[ 106 ]
You can also construct new objects with the use of projection queries. For example,
if you want to create a new object which has only the names and ingredients of
ice-creams, then the query would be as follows:
var projectionItems = from itms in db.


Pages:
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
katalog stron śmieszne dowcipy basen z piłeczkami dieta light życzenia ślubne