I am using Entity Framework code first.
I was trying to put 2 foreign keys on the same table but I am not being allowed to do so.
It’s like that(edited) :
The table is called Avaliacao:
[Required]
public int AvaliacaoId { get; set; }
[Required]
public int LivroId { get; set; }
public int? AutorId { get; set; }
public virtual Livro Livro { get; set; }
public virtual Autor Autor { get; set; }
I wanted AutorId not to be null but it only works that way.
I wish I could have 2 non-nullable FK but only one Delete on Cascade.
How do I achieve this with Entity Framework code-first?
Somebody help me please
thx in advance
ZeCarioca
EDIT:
I have not tested this, but if you are using EF5 you could make use of the OnModelCreating method by overiding it in your DbContext. You can call the same entity multiple times to add configuration so you could specify a second foreign key, set its HasRequired property and set its WillCascadeOnDelete property to true.
Something like this for the first foreign key.
For more reference on the method you can look here at the MSDN Docs: DbModelBuilder
As mentioned I have not tested this myself so you might need to change some of the properties.
Hope it helps