Prev | Current Page 162 | Next

Satheesh, N Kumar

"LINQ Quickly"

As we have the collection of classes referred in the main class, we can refer
to the objects easily. For example, we would be writing the query as follows to join
two tables for the query without using the relationship.
var qry = from cat in db.Categories
join items in db.Items on cat.CategoryID equals item.CategoryID
where cat.Category == "Icecreams"
select new { itms.Name, itms.Categories.Category };
If we have table collections defined inside the class, the same query will look like
this:
var query = from itms in db.Items
where itms.Categories.Category == "Icecream"
select new { itms.Name, itms.Categories.Category };
This query uses the table collection defined in the entity classes, and we use the
object members directly in the query where clause. Following is the query built by
LINQ to SQL for both the query expressions.
query = {Select [t0].[Name], [t1].[Category]
from [Items] as [t0]
inner join [Categories] as [t1] ON [t1].[CategoryID] =
[t0].[CategoryID]
where [t1].[Category] = @p0}
Remote Queries and Local Queries
We have seen some query expressions like this:
string category = "Icecreams";
Categories icecreams = dbDeserts.


Pages:
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
praca w holandii wierszyki życzenia pensjonaty w beskidach pozycjonowanie