Prev | Current Page 173 | Next

Satheesh, N Kumar

"LINQ Quickly"


var QueriesCategory =
from s in db.Categories
join c in db.Items on s.CategoryID equals c.CategoryID into
categoryitems
select new { s, categoryitems };
The following screenshot shows a query that is generated by LINQ to SQL and is
assigned to the variable QueriesCategory:
Chapter 4
[ 109 ]
Raw SQL Query
In some cases, we may feel that the DLINQ query is not sufficient enough to handle
a query or we may just want to have a direct SQL query to be performed against
the database. We used to perform this using the SQLCommand object, having the
command type as text and the command text will have the raw SQL query as text.
This way of executing the raw SQL, directly against the database is also possible
using DataContext. DataContext has a method, ExecuteQuery, which takes the
query text as a parameter, and converts the results to objects.
IEnumerable results = db.ExecuteQuery
(@"select c1.category as Category, c2.Name as ItemName
from category as c1, Items as c2
where c1.categoryID = c2.


Pages:
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
pustaki szklane House Extension Kąty Rybackie noclegi kasyno Kołobrzeg