“Fonction de fonctionnement LINQ SELECT” Réponses codées

Fonction de fonctionnement LINQ SELECT

// Notice that code for calculating price is repeated

var q = 
  from p in db.Products
    where (p.UnitPrice * 1.19m) > 30.0m
    select new
      { 
        p.ProductName, 
        OriginalPrice = p.UnitPrice,
        ShopPrice = (p.UnitPrice * 1.19m)
      };
Quaint Quelea

Fonction de fonctionnement LINQ SELECT

// Lambda expression that calculates the price
Expression<Func<Nwind.Product, decimal?>> calcPrice = 
  (p) => p.UnitPrice * 1.19m;

// Query that selects products

var q = 
  from p in db.Products.ToExpandable()

  where calcPrice.Invoke(p) > 30.0m
    select new 
      { 
        p.ProductName, 
        OriginalPrice = p.UnitPrice,
        ShopPrice = calcPrice.Invoke(p)
      };
Quaint Quelea

Réponses similaires à “Fonction de fonctionnement LINQ SELECT”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code