コード例 #1
0
 public UnitOfWork(SocialMediaContext context)
 {
     AppContext = context;
     Users      = new UserRepository(context.Users);
     Posts      = new PostsRepository(context.Posts);
     Followings = new FollowRepository(context.Followings);
 }
コード例 #2
0
        public static void Initialize(SocialMediaContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.Users.AddRange(new List <UserEntity>
            {
                new UserEntity
                {
                    Email    = "*****@*****.**",
                    Login    = "******",
                    Password = "******",
                    Status   = UserStatus.Unauthorized,
                    Image    = System.IO.File.ReadAllBytes("event.png")
                },
                new UserEntity
                {
                    Email    = "*****@*****.**",
                    Login    = "******",
                    Password = "******",
                    Status   = UserStatus.Unauthorized,
                    Image    = System.IO.File.ReadAllBytes("event.png")
                },
                new UserEntity
                {
                    Email    = "chel3232",
                    Login    = "******",
                    Password = "******",
                    Status   = UserStatus.Unauthorized,
                    Image    = System.IO.File.ReadAllBytes("event.png")
                }
            });
            context.SaveChanges();

            context.Followings.AddRange(new List <FollowEntity>
            {
                new FollowEntity
                {
                    FollowerId = 1,
                    FollowedId = 2
                },
                new FollowEntity
                {
                    FollowerId = 2,
                    FollowedId = 2
                }
            });
            context.SaveChanges();

            var u = context.Users.ToList();
            var q = context.Followings.ToList();
        }