Prev | Current Page 172 | Next

Satheesh, N Kumar

"LINQ Quickly"

For example, to get all the items that belong to a particular category in
the Categories table, we usually join both the tables using the query and fetch
the details. However in LINQ to SQL, it is not always the case. We can join
LINQ to SQL
[ 108 ]
tables irrespective of their relationship. For example, we can fetch records from the
Categories and Items table in which CategoryID is a key field in the Category
table, and is the foreign key in the Items table, which identifies the corresponding
items. The following code fetches the category from the Categories table and
the corresponding item name from the Items table having a join on the
CategoryID field.
var QryCategory =
from s in db.Categories
join c in db.Items on s.CategoryID equals c.CategoryID
select new {catgry = s.Category,itemname = c.Name};
The variable, QryCategory, in the query will contain query text which is shown
as follows:
The following query is another example of a join query which extracts information
from both the tables and inserts the rows into a new runtime table.


Pages:
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
Spa Ciechocinek drzwiowe hosting hotele londyn xiden.bosten.pl