本文整理汇总了C#中IProductRepository.GetById方法的典型用法代码示例。如果您正苦于以下问题:C# IProductRepository.GetById方法的具体用法?C# IProductRepository.GetById怎么用?C# IProductRepository.GetById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProductRepository
的用法示例。
在下文中一共展示了IProductRepository.GetById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CartViewModel
public CartViewModel(Cart cart, IProductRepository productRepository)
{
_cart = cart;
_items = new List<CartItemViewModel>();
foreach( var item in cart.Items )
{
var product = productRepository.GetById(item.ProductId);
var cartItemViewModel = new CartItemViewModel(item, product);
_items.Add(cartItemViewModel);
}
}
示例2: SampleMethod
private static void SampleMethod(IProductRepository productRepo)
{
SessionProvider.RebuildSchema();
//Add a Unit of Measure
var uomCrate = new UnitOfMeasure { UomDescription = "Crate" };
productRepo.SaveUOM(uomCrate);
//Add some categories
var catA = new Category { CategoryName = "Metals" };
var catB = new Category { CategoryName = "Plastics" };
var catC = new Category { CategoryName = "Recycled Goods" };
var catD = new Category { CategoryName = "New Materials" };
productRepo.SaveCategory(catA);
productRepo.SaveCategory(catB);
productRepo.SaveCategory(catC);
productRepo.SaveCategory(catD);
//Add some products
var prod01 = new Product { ProductName = "Copper Wire", UOM = uomCrate };
var prod02 = new Product { ProductName = "Refurbished Sprockets", UOM = uomCrate };
var prod03 = new Product { ProductName = "Plastic Housings", UOM = uomCrate };
var prod04 = new Product { ProductName = "Used Bubble Wrap", UOM = uomCrate };
//Assign some Categories
prod01.Categories.Add(catA);
prod01.Categories.Add(catD);
prod02.Categories.Add(catA);
prod02.Categories.Add(catC);
prod03.Categories.Add(catB);
prod03.Categories.Add(catD);
prod04.Categories.Add(catB);
prod04.Categories.Add(catC);
//Persist our objects
productRepo.Save(prod01);
productRepo.Save(prod02);
productRepo.Save(prod03);
productRepo.Save(prod04);
var prodTemp = productRepo.GetById(prod01.ProductId);
prodTemp.Categories.RemoveAt(0);
System.Console.WriteLine("Press any key to continue...");
System.Console.Read();
}