public void Init() { var mockGuidQueue = GuidHelper.CreateMockGuidQueue(4); var admin = new Account(); admin.Id = mockGuidQueue.Dequeue(); admin.Username = "******"; admin.CreateAt = new DateTime(2000, 1, 1); admin.Nick = "ADMIN"; admin.PasswordHash = "MockHash"; admin.PasswordSalt = "SALT"; _dbContext.Accounts.Add(admin); for (int i = 1; i <= 3; i++) { var account = new Account(); account.Id = mockGuidQueue.Dequeue(); account.Username = "******" + i; account.CreateAt = new DateTime(2000, 1, 1); account.Nick = "用户" + i; account.PasswordHash = "MockHash"; account.PasswordSalt = "SALT"; _dbContext.Accounts.Add(account); } _dbContext.SaveChanges(); }
public void InitAccounts(IList <Account> accounts) { if (accounts == null || accounts.Count == 0) { return; } var allAccounts = _context.Accounts.ToList(); foreach (var account in accounts) { var theOne = allAccounts.FirstOrDefault(x => x.Username == account.Username); if (theOne != null) { _context.Add(theOne); } } _context.SaveChanges(); }
public void TestMethod1() { using (AppDbContext appDb = new AppDbContext()) { appDb.Items.Add(new AppItems() { Name = "Item1", }); appDb.Items.Add(new AppItems() { Name = "Item2", }); appDb.Items.Add(new AppItems() { Name = "Item3", }); appDb.SaveChanges(); } using (FooDbContext fooDb = new FooDbContext()) { fooDb.FooItems.Add(new FooItems() { Name = "Foo1", }); fooDb.FooItems.Add(new FooItems() { Name = "Foo2", }); fooDb.FooItems.Add(new FooItems() { Name = "Foo3", }); fooDb.SaveChanges(); } // Query saved items using (AppDbContext appDb = new AppDbContext()) { var items = appDb.Items.ToList(); items.ForEach(c => log.Info("AppItem:" + c.Guid.ToString() + " name:" + c.Name)); } using (FooDbContext fooDb = new FooDbContext()) { var items = fooDb.FooItems.ToList(); items.ForEach(c => log.Info("FooItem: " + c.Guid.ToString() + " name:" + c.Name)); } }
public void ProcessFile(string source, string filePath) { _fooDb.Foos.AddRange(GetFileReader().ReadFile(filePath)); _fooDb.SaveChanges(); }