Beispiel #1
0
        //using (var context = new CarRentalContext())
        //{
        //    ManyToManyRelationship(context);
        //}
        private static void ManyToManyRelationship(CarRentalContext context)
        {
            var car1 = new Car
            {
                BrandId    = 1,
                ColorId    = 1,
                CarTypeId  = 1,
                Model      = "Focus",
                Capacity   = 4,
                ModelYear  = "2018",
                DailyPrice = 150,
            };
            var car2 = new Car
            {
                Model      = "Fiesta",
                ModelYear  = "2012",
                ColorId    = 1,
                BrandId    = 1,
                CarTypeId  = 1,
                Capacity   = 4,
                DailyPrice = 100,
            };

            context.AddRange(
                //new Brand
                //{
                //    Name = "Ford"
                //},
                //new Color
                //{
                //    Name = "Siyah"
                //},
                //new CarType
                //{
                //    Name = "Hatchback"
                //},
                //new Department
                //{
                //    Name = "Satış"
                //},
                //new Employee
                //{
                //    IdentityNo = "23456789101",
                //    FirstName = "Ahmet",
                //    LastName = "Çalışkan",
                //    Gender = 'M',
                //    DOB = Convert.ToDateTime("12/24/1987"),
                //    Address = "İzmir",
                //    PhoneNumber = "05554443322",
                //    Email = "*****@*****.**",
                //    PasswordHash = "23456",
                //    DepartmentId = 1,
                //    Position = "Satis Temsilcisi",
                //    JoinDate = DateTime.Now
                //},
                //new IndividualCustomer
                //{
                //    IdentityNo = "12345678910",
                //    FirstName = "Ali",
                //    LastName = "Yaman",
                //    DOB = Convert.ToDateTime("10/10/1990"),
                //    PhoneNumber = "05556667788",
                //    Address = "İzmir",
                //    Email = "*****@*****.**",
                //    PasswordHash = "12345",
                //    JoinDate = DateTime.Now
                //},
                new Rental
            {
                CustomerId = 2,
                EmployeeId = 1,
                RentDate   = DateTime.Now,
                TotalPrice = 100,
                Discount   = 0
            },
                new Rental
            {
                CustomerId = 2,
                EmployeeId = 1,
                RentDate   = DateTime.Now,
            });
            context.SaveChanges();
        }