“LINQ Pilih Fungsi Operasi” Kode Jawaban

LINQ Pilih Fungsi Operasi

// 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

LINQ Pilih Fungsi Operasi

// 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

Jawaban yang mirip dengan “LINQ Pilih Fungsi Operasi”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya