c# - Entity Framework Table Splitting: not in the same type hierarchy / do not have a valid one to one foreign key relationship -


i'm using entity framework 6 code-first approach, , want 2 entities put in same table. doing wrong?

[table("review")] public class review {     public int id { get; set; }     public pictureinfo pictureinfo { get; set; }     public int pictureinfoid { get; set; } }  [table("review")] public class pictureinfo {     [key, foreignkey("review")]     public int reviewid { get; set; }     public review review { get; set; } } 

the error get: entity types 'pictureinfo' , 'review' cannot share table 'review' because not in same type hierarchy or not have valid 1 one foreign key relationship matching primary keys between them.

what doing wrong?

seems problem relationship interpreted one-to-0..1 instead of one-to-one.

the foreign key int pictureinfoid on review end unneeded/ignored, non-nullability did not make review end of relationship required. removing unneeded key , adding [required] attribute pictureinfo navigational property solved it.

here's corrected review class.

[table("review")] public class review {     public int id { get; set; }     [required]     public pictureinfo pictureinfo { get; set; } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -