Gleiches Projektions -MAPPPing in iQueryable.Select, aber mit unterschiedlichen Kindersammlungsfiltern in EF6C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Gleiches Projektions -MAPPPing in iQueryable.Select, aber mit unterschiedlichen Kindersammlungsfiltern in EF6

Post by Anonymous »

Ich habe Methoden, die in iQueryable verwendet werden. Das Problem ist, dass es viele verschiedene Möglichkeiten benötigt, um die Kindersammlungen zu filtern. Dies bedeutet, dass sie alle dieselbe Zuordnungslogik teilen, um Parententity an parentDTO zuzuordnen. Daher versuche ich, diese Mapping -Logik zu extrahieren. Hat der nestierte Ausdruck von Linq korrekt in SQL übersetzt.) Außerdem verwende ich .NET Framework 4.8 mit Entity Framework 6. < /p>
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))
};
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post