コード例 #1
0
 private static User GetUserByLogin(string userName)
 {
     using (var context = new IdSDbContext(new DbContextOptions <IdSDbContext>()))
     {
         return(context.Users.SingleOrDefault(x => x.Login == userName));
     }
 }
コード例 #2
0
        private static void Seed()
        {
            using (var db = new IdSDbContext(new DbContextOptions <IdSDbContext>()))
            {
                if (db.Database.EnsureDeleted())
                {
                    db.Database.Migrate();
                    var users = Enumerable.Range(1, 5).Select(i => new User
                    {
                        Id       = i,
                        Login    = "******" + i,
                        Password = "******" + i,
                        Name     = "name" + i,
                        Surname  = "surname" + i
                    });

                    db.Users.AddRange(users);
                    db.SaveChanges();
                }
            }
        }