I'm not a "MacGyver", so I need help from how to do Frankenstein's tables work with circular reference works in EF. (facepalm) This is a old database on postgresql and I need it work on a new web sistem (!!!). So, I think I need a jerry-rigged here :)
Table A
int id PK;
varchar description;
varchar other_field
...
int idTableB FK (reference Table B key)
Table B
int id PK
varchar fieldX
double fiendY
...
int idTableA FK (reference Table A key)
If I try use models with ForeignKey attribute, get the error on attached image.
Models with these error are like:
Models
[table("table_a")]
public class ModelA {
[Key, Column("id")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set;]
[Column("idTableB")]
public int IdTableB { get; set; }
[ForeignKey("IdTableB")]
public virtual ModelB Model_B { get; set; }
}
[table("table_b")]
public class ModelB {
[Key, Column("id")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set;]
[Column("idTableA")]
public int IdTableA { get; set; }
[ForeignKey("IdTableA")]
public virtual ModelA Model_A { get; set; }
}
Well, a object of ModelA refers to a object of ModelB with in turn makes references to another object of Model A, with in turn makes references to any ModelB object, may be the same as references it... OMG!
Yes! I'm working with DatabaseFirst. And it is a simple but very close to reality example. Has any magician here to help me to solve it? Thanks guys.