BlazorDB icon indicating copy to clipboard operation
BlazorDB copied to clipboard

Set other side of a relationship automatically

Open chanan opened this issue 6 years ago • 0 comments

For example:

var person = new Person { FirstName = "Many", LastName = "Test" };
var address1 = new Address { Street = "Many test 1", City = "Saved as a reference" };
var address2 = new Address { Street = "Many test 2", City = "Saved as a reference" };
person.OtherAddresses = new List<Address> { address1, address2 };
Context.People.Add(person);
Context.SaveChanges();

Right now, in the above code snippet there is no navigation property from Address to Person. If one was added to Address it would have to be manually set to the person instance:

var person = new Person { FirstName = "Many", LastName = "Test" };
var address1 = new Address { Street = "Many test 1", City = "Saved as a reference", Person = person };
var address2 = new Address { Street = "Many test 2", City = "Saved as a reference", Person = person };
person.OtherAddresses = new List<Address> { address1, address2 };
Context.People.Add(person);
Context.SaveChanges();

Make this automatic in SaveChanges()

chanan avatar Jun 02 '18 15:06 chanan