I'm trying to update a graph where the child is just for linking to the grandchild, however the child is inserted with only NULL values leaving the grandchild unlinked. How can I solve this?
My code
_db.UpdateGraph(sector, up =>up.OwnedEntity(s =>s.Image, date =>date.OwnedEntity(i =>i.Picture)));
Executed SQL:
SET SESSION sql_mode='ANSI';INSERT INTO`Images`(
`PictureId`, `PhotoId`) VALUES (
NULL, NULL);
SELECT`Id`FROM`Images`WHERE row_count() >0AND`Id`=last_insert_id();
SET SESSION sql_mode='ANSI';INSERT INTO`Pictures`(
`Logo`, `Path`, `Description`, `Created`) VALUES (
0, '/User_Data/Misc/2016/5/12/Untitled.gif'/* @gp1 */, NULL, 5/12/20169:05:13 AM /* @gp2 */);
SELECT`Id`FROM`Pictures`WHERE row_count() >0AND`Id`=last_insert_id()
My models:
publicclassSector{publicintId{get;set;}publicstringName{get;set;}publicboolActive{get;set;}publicint?ImageId{get;set;}publicvirtualImageImage{get;set;}}publicclassImage{publicintId{get;set;}publicint?PictureId{get;set;}publicPicturePicture{get;set;}publicint?PhotoId{get;set;}publicPhotoPhoto{get;set;}publicvirtualICollection<Sector>Sectors{get;set;}}publicclassPicture{publicintId{get;set;}publicstringPath{get;set;}publicstringDescription{get;set;}publicDateTimeCreated{get;set;}}Code first configuration:
publicclassImageEntityConfig:EntityTypeConfiguration<Image>{publicImageEntityConfig(){HasOptional(i =>i.Picture).WithMany().HasForeignKey(i =>i.PictureId);HasOptional(i =>i.Photo).WithMany().HasForeignKey(i =>i.PhotoId);}}
I'm trying to update a graph where the child is just for linking to the grandchild, however the child is inserted with only NULL values leaving the grandchild unlinked. How can I solve this?
My code
Executed SQL:
My models:
Code first configuration: