Mercurial > pub > bltoolkit
comparison Demo/Asp.Net/BusinessLogic/DataAccess/ProductAccessor.cs @ 0:f990fcb411a9
Копия текущей версии из github
| author | cin |
|---|---|
| date | Thu, 27 Mar 2014 21:46:09 +0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f990fcb411a9 |
|---|---|
| 1 using System; | |
| 2 using System.Collections.Generic; | |
| 3 | |
| 4 using BLToolkit.Aspects; | |
| 5 using BLToolkit.Data; | |
| 6 using BLToolkit.DataAccess; | |
| 7 | |
| 8 namespace PetShop.BusinessLogic.DataAccess | |
| 9 { | |
| 10 using ObjectModel; | |
| 11 | |
| 12 public abstract class ProductAccessor : AccessorBase<ProductAccessor.DB, ProductAccessor> | |
| 13 { | |
| 14 public class DB : DbManager { public DB() : base("ProductDB") {} } | |
| 15 | |
| 16 #region Item | |
| 17 | |
| 18 const string _itemQuery = @" | |
| 19 SELECT | |
| 20 i.*, | |
| 21 n.Qty, | |
| 22 p.Name as ProductName, | |
| 23 p.CategoryId | |
| 24 FROM | |
| 25 Item i | |
| 26 JOIN Product p ON p.ProductId = i.ProductId | |
| 27 JOIN Inventory n ON n.ItemId = i.ItemId"; | |
| 28 | |
| 29 [SqlQuery(_itemQuery + @" WHERE i.ProductId = @id")] | |
| 30 public abstract IList<Item> GetItemListByProductID(string @id); | |
| 31 | |
| 32 [SqlQuery(_itemQuery + @" WHERE i.ItemId = @itemID")] | |
| 33 public abstract Item GetItem(string @itemID); | |
| 34 | |
| 35 [SqlQuery(_itemQuery + @" ORDER BY i.Name")] | |
| 36 public abstract List<Item> GetAllItemList(); | |
| 37 | |
| 38 #endregion | |
| 39 | |
| 40 #region Product | |
| 41 | |
| 42 [Cache(MaxMinutes = 60)] | |
| 43 [SqlQuery(@"SELECT * FROM Product WHERE CategoryId = @id")] | |
| 44 public abstract IList<Product> GetProductListByCategoryID(string @id); | |
| 45 | |
| 46 #endregion | |
| 47 | |
| 48 #region Categoty | |
| 49 | |
| 50 // This method needs to be cached, so we can't call Query.SelectByKey directly from the manager class. | |
| 51 // | |
| 52 [Cache(MaxMinutes=60)] | |
| 53 public virtual Category GetCategory(string id) | |
| 54 { | |
| 55 return Query.SelectByKey<Category>(id); | |
| 56 } | |
| 57 | |
| 58 #endregion | |
| 59 | |
| 60 #region Inventory | |
| 61 | |
| 62 [SqlQuery(@"SELECT Qty FROM Inventory WHERE ItemId = @itemId")] | |
| 63 public abstract int CurrentQtyInStock(string @itemId); | |
| 64 | |
| 65 #endregion | |
| 66 } | |
| 67 } |
