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() > 0 AND `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/2016 9:05:13 AM /* @gp2 */);
SELECT
`Id`
FROM `Pictures`
WHERE row_count() > 0 AND `Id`=last_insert_id()
My models:
public class Sector
{
public int Id { get; set; }
public string Name { get; set; }
public bool Active { get; set; }
public int? ImageId { get; set; }
public virtual Image Image { get; set; }
}
public class Image
{
public int Id { get; set; }
public int? PictureId { get; set; }
public Picture Picture { get; set; }
public int? PhotoId { get; set; }
public Photo Photo { get; set; }
public virtual ICollection<Sector> Sectors { get; set; }
}
public class Picture
{
public int Id { get; set; }
public string Path { get; set; }
public string Description { get; set; }
public DateTime Created { get; set; }
}
Code first configuration:
public class ImageEntityConfig : EntityTypeConfiguration<Image>
{
public ImageEntityConfig()
{
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: