There is MS Visual Studio 2010 and MS .NET Framework 4 application PassGuideApp.
PassGuideApp connects to a MS SQL Server 2008 database PassGuideDB.
LINQ to SQL is used to define classes.
There are two objects named Product and Products_details.
There is a one-to-many relation from Product to Product_details on the ProductID field.
The Products_details table include the fields Weight and NumberOf
The total weight of each Product need to be calculated.
How can this be achieved?
A.
dataContext.Product_Details GroupJoin (dataContext.Product, d => d.ProductID,
o => o.ProductlD, (dts, ord) => new { ProductID = dts.ProductID),
TotalAmount = dts.Weight * dts.NumberOf})
B.
dataContext.Products GroupJoin(datacontext.Product Details p => p.ProductlD, d => d,
ProductID, (prod, dts) => new (ProductID) = prod.ProductID, CustomerID = prod.CustomerlD,
TotalAmount = dts.Sum(pd => pd.Weight * pd.NumberOf))
C.
from Product in dataContext.Product group Product by Product.ProductID into k join details in
dataContext.Product_Details on k.Key equals details.ProductID select new {ProductID =
details.ProductID, TotalAmount = details.Weight*details.NumberOf}
Explanation: