I have the following situation: my database is MySql, when I try to delete a direct record in the bank, from this message:
Cannot delete or update a parent row: a foreign key constraint fails ('lifeproject'.'t0041_usuario', CONSTRAINT 'fk_t0041_usuario_t0040_grupo_usuario1' FOREIGN KEY ('t0040_id_grupo') REFERENCES 't0040_grupo_usuario' ('t0040_id_grupo') ON UPDATE CASCADE)
Ok, this is correct, that's exactly what I need, but when I try to delete by the application, the On Delete restrict, which is set in the table creation, is not respected. I'm using Entity Framewrok 6. I understand that when trying to delete by the application, Mysql should fire the same constraint exception for the application. Can someone give me some help?
Here is the group classUsers
[Table("t0040_grupo_usuario")]
public class GrupoUsuarioModel
{
#region propriedades
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string t0040_id_grupo { get; set; }
[Required]
public string t0040_descricao { get; set; }
[Required]
public int t0020_id_empresa { get; set; }
[ForeignKey("t0020_id_empresa")]
public virtual EmpresaModel EmpresaModel { get; set; }
public virtual ICollection<UsuarioModel> UsuarioModel { get; set; }
public virtual ICollection<AcessoModel> AcessoModel { get; set; }
#endregion
}
}
Here are the users class
[Table("t0041_usuario")]
public class UsuarioModel
{
#region propriedades
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int t0041_id_usuario { get; set; }
[Required]
public string t0041_nome_usuario { get; set; }
[Required]
public string t0040_id_grupo { get; set; }
[Required]
public string t0041_descricao { get; set; }
[Required]
public string t0041_senha { get; set; }
[Required]
public int t0020_id_empresa { get; set; }
[ForeignKey("t0020_id_empresa")]
public virtual EmpresaModel EmpresaModel { get; set; }
[ForeignKey("t0040_id_grupo")]
public virtual GrupoUsuarioModel GrupoUsuarioModel { get; set; }
#endregion
}