public void GetDataTest_by_id() { var testGood = TestGood(); var controller = new GoodsContext(); var resultActual = controller.GetData(1).ToList(); Assert.AreEqual(testGood[0].Id, resultActual[0].Id); }
public void Test_PickSerialNumber() { string formatSerialNumber = null; bool saveFailed; do { saveFailed = false; using (var context = new GoodsContext()) { try { var serialNumber = context.SerialNumbers.Where(s => s.Date == DateTime.Now.Date).SingleOrDefault(); if (serialNumber == null) { serialNumber = new SerialNumber() { Date = DateTime.Now.Date, SomethingCount = 1 }; context.SerialNumbers.Add(serialNumber); } else { serialNumber.SomethingCount += 1; } context.SaveChanges(); formatSerialNumber = String.Format("{0:MMdd}-{1:00}", serialNumber.Date, serialNumber.SomethingCount); } catch (DbUpdateConcurrencyException concurrencyException) { saveFailed = true; //發生Concurrency update的問題,將memory中現有欄位值更新為資料庫的值 var entry = concurrencyException.Entries.Single(); entry.OriginalValues.SetValues(entry.GetDatabaseValues()); // Waiting 1~99ms Thread.Sleep(new Random(Guid.NewGuid().GetHashCode()).Next(1, 100)); } } } while (saveFailed); }
public BaseRepository(GoodsContext dbContext) { goodsContext = dbContext; }
public ImportanceRepository(GoodsContext goodsContext) : base(goodsContext) { }
public LoginController(GoodsContext context) { _context = context; }
public GoodRepository(GoodsContext goodsContext) : base(goodsContext) { }
public BillRepository(GoodsContext goodsContext) : base(goodsContext) { }
public GoodRepository(GoodsContext context) { _context = context; }
public AccountRepository(GoodsContext db) : base(db) { }
public UserRepository(GoodsContext goodsContext) : base(goodsContext) { }
public UsersController(GoodsContext context) { _context = context; }
public ImagesController(GoodsContext context) { _context = context; }
public TypesController(GoodsContext context) { _context = context; }
/* * /// <summary> * * public string ReturnUrl { get; set; } * public async Task OnGetAsync(string returnUrl = null) * { * using (var context = new CategoriesContext()) * { * ViewData["categories"] = await context.Categories.ToListAsync(); * ReturnUrl = returnUrl; * } * } * /// </summary> */ public Goods1Controller(GoodsContext context, ICategoryRepository categoryRepository, IWebHostEnvironment hostEnvironment) { _context = context; _categoryRepository = categoryRepository; webHostEnvironment = hostEnvironment; }
public CustomerService(ILifetimeScope container, IConfiguration configuration, ICacheService cacheService, GoodsContext goodsContext) { cacheService.InitCacheService(configuration.GetSection("modules:2:properties:RedisConnection").Value); //启动缓存客户端 goodsContext.Database.EnsureCreated(); //自动迁移数据库 }
public GoodsController(GoodsContext context) { db = context; }