You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server 2008 database. You create classes by using LINQ to
SQL based on the records shown in the exhibit. (Click the Exhibit button.)
You need to create a LINQ query to retrieve a list of objects that contains the OrderID and
CustomerID properties. You need to retrieve the total price amount of each Order record. What are
two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose
two.)
A.
from details in dataContext.Order_Detail
group details by details.OrderID into g
join order in dataContext.Orders on g.Key equals order.OrderID
select new {
OrderID = order.OrderID, CustomerID = order.CustomerID,
TotalAmount = g.Sum(od => od.UnitPrice * od.Quantity)
}
This is an Object Query. It looks at the Order Details EntitySet and creating a group g based on
OrderID.
* The group g is then joined with Orders EntitySet based on g.Key = OrderID
* For each matching records a new dynamic object containing OrderID, CustomerID and
TotalAmount is created.
* The dynamic records are the results returned in an INumerable Object, for later processing
Alterantive D. This is an Object Query. The GroupJoin method is used to join Orders to OrderDetails.
Parameters for GroupJoin:
1. An Order_Details EntitySet
2. Order o (from the Orders in the Orders Entity Set, picking up Order_id from both Entity Sets)
3. Order_ID from the first Order_Details record from the OD EnitySet
4. Lamda Expression passing ord and dts (ord=o, dts=d)
The body of the Lamda Expression is working out the total and Returning a Dynamic object as in A.
QUESTION 34
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server database. You use Entity SQL to retrieve data from
the database. You need to enable query plan caching. Which object should you use?
EntityCommand
B.
dataContext.Order_Detail.GroupJoin(dataContext.Orders,
d => d.OrderID,
o => o.OrderID,
(dts, ord) => new {
OrderID = dts.OrderID,
CustomerID = dts.Order.CustomerID,
TotalAmount = dts.UnitPrice * dts.Quantity
}
)
EntityConnection
C.
from order in dataContext.
Orders group order by order.OrderID into g
join details in dataContext.Order_Detail on g.Key equals details.OrderID
select new {
OrderID = details.OrderID,
CustomerID = details.Order.CustomerID,
TotalAmount = details.UnitPrice * details.Quantity
}
EntityTransaction
D.
dataContext.Orders.GroupJoin(dataContext.Order_Detail,
o => o.OrderID,
d => d.OrderID.
(ord, dts) => new {
OrderID = ord.OrderID,
CustomerID = ord.CustomerID,
TotalAmount = dts.Sum(od => od.UnitPrice * od.Quantity)
}
)
EntityDataReader
A.
from details in dataContext.Order_Detail
group details by details.OrderID into g
join order in dataContext.Orders on g.Key equals order.OrderID
select new {
OrderID = order.OrderID, CustomerID = order.CustomerID,
TotalAmount = g.Sum(od => od.UnitPrice * od.Quantity)
}
This is an Object Query. It looks at the Order Details EntitySet and creating a group g based on
OrderID.
* The group g is then joined with Orders EntitySet based on g.Key = OrderID
* For each matching records a new dynamic object containing OrderID, CustomerID and
TotalAmount is created.
* The dynamic records are the results returned in an INumerable Object, for later processing
Alterantive D. This is an Object Query. The GroupJoin method is used to join Orders to OrderDetails.
Parameters for GroupJoin:
1. An Order_Details EntitySet
2. Order o (from the Orders in the Orders Entity Set, picking up Order_id from both Entity Sets)
3. Order_ID from the first Order_Details record from the OD EnitySet
4. Lamda Expression passing ord and dts (ord=o, dts=d)
The body of the Lamda Expression is working out the total and Returning a Dynamic object as in A.
QUESTION 34
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server database. You use Entity SQL to retrieve data from
the database. You need to enable query plan caching. Which object should you use?
EntityCommand
A.
from details in dataContext.Order_Detail
group details by details.OrderID into g
join order in dataContext.Orders on g.Key equals order.OrderID
select new {
OrderID = order.OrderID, CustomerID = order.CustomerID,
TotalAmount = g.Sum(od => od.UnitPrice * od.Quantity)
}
This is an Object Query. It looks at the Order Details EntitySet and creating a group g based on
OrderID.
* The group g is then joined with Orders EntitySet based on g.Key = OrderID
* For each matching records a new dynamic object containing OrderID, CustomerID and
TotalAmount is created.
* The dynamic records are the results returned in an INumerable Object, for later processing
Alterantive D. This is an Object Query. The GroupJoin method is used to join Orders to OrderDetails.
Parameters for GroupJoin:
1. An Order_Details EntitySet
2. Order o (from the Orders in the Orders Entity Set, picking up Order_id from both Entity Sets)
3. Order_ID from the first Order_Details record from the OD EnitySet
4. Lamda Expression passing ord and dts (ord=o, dts=d)
The body of the Lamda Expression is working out the total and Returning a Dynamic object as in A.
QUESTION 34
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server database. You use Entity SQL to retrieve data from
the database. You need to enable query plan caching. Which object should you use?
EntityCommand
B.
dataContext.Order_Detail.GroupJoin(dataContext.Orders,
d => d.OrderID,
o => o.OrderID,
(dts, ord) => new {
OrderID = dts.OrderID,
CustomerID = dts.Order.CustomerID,
TotalAmount = dts.UnitPrice * dts.Quantity
}
)
EntityConnection
C.
from order in dataContext.
Orders group order by order.OrderID into g
join details in dataContext.Order_Detail on g.Key equals details.OrderID
select new {
OrderID = details.OrderID,
CustomerID = details.Order.CustomerID,
TotalAmount = details.UnitPrice * details.Quantity
}
EntityTransaction
D.
dataContext.Orders.GroupJoin(dataContext.Order_Detail,
o => o.OrderID,
d => d.OrderID.
(ord, dts) => new {
OrderID = ord.OrderID,
CustomerID = ord.CustomerID,
TotalAmount = dts.Sum(od => od.UnitPrice * od.Quantity)
}
)
EntityDataReader
Explanation:
AlterantiveWhenever an attempt to execute a query is made, the query pipeline looks up its query plan cache
to see whether the exact query is already compiled and available.
If so, it reuses the cached plan rather than building a new one. If a match is not found in the query
plan cache, the query is compiled and cached.
A query is identified by its Entity SQL text and parameter collection (names and types). All text
comparisons are case-sensitive.
Query plan caching is configurable through the EntityCommand.
To enable or disable query plan caching through System.Data.EntityClient.EntityCommand.
EnablePlanCaching, set this property to true or false.
Disabling plan caching for individual dynamic queries that are unlikely to be used more then once
improves performance.
You can enable query plan caching through EnablePlanCaching.
Query Plan Caching
(http://msdn.microsoft.com/en-us/library/bb738562.aspx)