Unten ist der Code, den ich jetzt habe (und die generierte SQL-Abfrage sieht gut aus.
Code: Select all
/*DAO methods*/
public List ListProductsFilteredByLabelCustomerID
(string productType, string customerID)
{
return context.Product
.AsExpandable()
.Where(product => product.ProductType == productType)
.Select(ToDTOFilteredByLabelCustomerID(customerID));
}
public List ListProductsFilteredByLabelCustomerType
(string productType, string customerType)
{
return context.Product
.AsExpandable()
.Where(product => product.ProductType == productType)
.Select(ToDTOFilteredByLabelCustomerType(customerID));
}
/*Projection Expressions*/
public static Expression
ToDTOFilteredByLabelCustomerID(string customerID)
{
return product => new ProductLabelsDTO {
productName = product.Name,
productDescription = product.Description,
// and a bunch of other product fields
//...
productSKU = product.SKU,
Labels = product.Labels
.Where(label => label.CustomerID == customerID)
.Select(label => LabelDTO.ToDTO().Invoke(label))
};
}
public static Expression
ToDTOFilteredByLabelCustomerType(string customerType)
{
return product => new ProductLabelsDTO {
productName = product.Name,
productDescription = product.Description,
// and a bunch of other product fields
//...
productSKU = product.SKU,
Labels = product.Labels
.Where(label => label.CustomerType == customerType)
.Select(label => LabelDTO.ToDTO().Invoke(label))
};
}