public void UserUserProfileTest()
 {
     Database.SetInitializer<EFDbContext>(new CreateDatabaseIfNotExists<EFDbContext>());
     using (var context = new EFDbContext())
     {
         context.Database.Create();
         User user = new User
         {
             UserName = "******",
             Password = "******",
             Email = "*****@*****.**",
             AddedDate = DateTime.Now,
             ModifiedDate = DateTime.Now,
             IP = "1.1.1.1",
             UserProfile = new UserProfile
             {
                 FirstName = "Frankelly",
                 LastName = "Veras",
                 Address = "Sto.Dgo",
                 AddedDate = DateTime.Now,
                 ModifiedDate = DateTime.Now,
                 IP = "1.1.1.1"
             },
         };
         context.Entry(user).State = System.Data.Entity.EntityState.Added;
         context.SaveChanges();
     }
 }
 public void CustomerOrderTest()
 {
     Database.SetInitializer<EFDbContext>(new CreateDatabaseIfNotExists<EFDbContext>());
     using (var context = new EFDbContext())
     {
         context.Database.Create();
         Customer customer = new Customer
         {
             Name = "Frankelly",
             Email = "*****@*****.**",
             AddedDate = DateTime.Now,
             ModifiedDate = DateTime.Now,
             IP = "1.1.1.1",
             Orders = new List<Order>{
                                     new Order
                                     {
                                         Quantity = 12,
                                         Price =15,
                                         AddedDate = DateTime.Now,
                                         ModifiedDate = DateTime.Now,
                                          IP = "1.1.1.1",
                                     },
                                     new Order
                                     {
                                         Quantity = 10,
                                         Price =25,
                                         AddedDate = DateTime.Now,
                                         ModifiedDate = DateTime.Now,
                                          IP = "1.1.1.1",
                                     }
                                 }
         };
         context.Entry(customer).State = System.Data.Entity.EntityState.Added;
         context.SaveChanges();
     }
 }
 public Repository(EFDbContext con) => context = con;
Beispiel #4
0
 public Repository(EFDbContext context)
 {
     this.context = context;
 }
Beispiel #5
0
 public UnitOfWork()
 {
     context = new EFDbContext();
 }
Beispiel #6
0
 public UnitOfWork(EFDbContext context)
 {
     this.context = context;
 }
Beispiel #7
0
 public UnitOfWork(EFDbContext eFDbContext)
 {
     _context = eFDbContext;
 }
Beispiel #8
0
 public Repository(EFDbContext context)
 {
     _context  = context;
     _entities = _context.Set <T>();
 }
 public UnitOfWork()
 {
     db = new EFDbContext(); //构造函数中初始化上下文对象
 }
 public UnitOfWork(EFDbContext context)
 {
     this.db = context;  //构造函数中初始化上下文对象
 }
 public void StudentCourseTest()
 {
     Database.SetInitializer<EFDbContext>(new CreateDatabaseIfNotExists<EFDbContext>());
     using (var context = new EFDbContext())
     {
         context.Database.Create();
         Student student = new Student
         {
             Name = "Franky",
             Age = 25,
             IsCurrent = true,
             AddedDate = DateTime.Now,
             ModifiedDate = DateTime.Now,
             IP = "1.1.1.1",
             Courses = new List<Course>{
                 new Course
                 {
                     Name = "Asp.Net",
                     MaximumStrength = 12,
                     AddedDate = DateTime.Now,
                     ModifiedDate = DateTime.Now,
                     IP = "1.1.1.1"
                 },
                  new Course
                 {
                     Name = "SignalR",
                     MaximumStrength = 12,
                     AddedDate = DateTime.Now,
                     ModifiedDate = DateTime.Now,
                     IP = "1.1.1.1"
                 }
             }
         };
         Course course = new Course
         {
             Name = "Web API",
             MaximumStrength = 12,
             AddedDate = DateTime.Now,
             ModifiedDate = DateTime.Now,
             IP = "1.1.1.1",
             Students = new List<Student>{
                 new Student
                 {
                     Name = "Franky",
                     Age = 25,
                     IsCurrent = true,
                     AddedDate = DateTime.Now,
                     ModifiedDate = DateTime.Now,
                     IP = "1.1.1.1",
                 },
                  new Student
                 {
                   Name = "Frandy",
                 Age = 25,
                 IsCurrent = true,
                 AddedDate = DateTime.Now,
                 ModifiedDate = DateTime.Now,
                 IP = "1.1.1.1",
                 }
             }
         };
         context.Entry(student).State = System.Data.Entity.EntityState.Added;
         context.Entry(course).State = System.Data.Entity.EntityState.Added;
         context.SaveChanges();
     }
 }