This question is locked. New answers and comments are not allowed.
I followed the instructions in the tutorial "How to: Manage One-to-Many Associations":
categoryConfiguration.HasAssociation(x => x.Cars). HasFieldName("_cars").WithOpposite(x => x.Category). ToColumn("CategoryID").HasConstraint((y, x) => x.CategoryID == y.CategoryID ). IsManaged().WithDataAccessKind(DataAccessKind.ReadWrite);carConfiguration.HasAssociation(x => x.Category). HasFieldName("_category").WithOpposite(x => x.Cars). ToColumn("CategoryID").HasConstraint((x, y) => x.CategoryID == y.CategoryID ). IsManaged().WithDataAccessKind(DataAccessKind.ReadWrite);using (FluentModel dbContext = new FluentModel()){ Car newCar = new Car(); newCar.Make = "Audi"; newCar.Model = "A8"; Category newCategory = new Category(); newCategory.CategoryName = "MyCategory"; dbContext.Add(newCategory); newCategory.Cars.Add(newCar); dbContext.SaveChanges();}
but when i want to add more than one car to newCategory.Cars :
using (FluentModel dbContext = new FluentModel()){ Car newCar1 = new Car(); newCar1.Make = "Audi"; newCar1.Model = "A8"; Car newCar2 = new Car(); newCar2.Make = "Volkswagen"; newCar2.Model = "Passat"; Category newCategory = new Category(); newCategory.CategoryName = "MyCategory"; dbContext.Add(newCategory); newCategory.Cars.Add(newCar1); newCategory.Cars.Add(newCar2); dbContext.SaveChanges();}Only one Car is saved !!
Help please