0

I start learning the Entity framework core. I am using Dotnet core 6 with entity framework core 6. I am working on a practice project in which I have three tables, named User, Key, and File.

The user table has the below properties:

    [Key]
    public Guid UserId { get; set; }
    public string Email { get; set; }
    public ICollection<SKey> SKey { get; set; }
    public ICollection<SFile> SFile { get; set; }

Key table:

    [Key]
    public Guid KeyId { get; set; }
    [ForeignKey("UserIdFK")]
    public Guid UserId { get; set; }
    public virtual SUser SUser { get; set; }
    public string? Key { get; set; }
    public ICollection<SFile> SFile { get; set; }

and the File table:

    [Key]
    public Guid FileId { get; set; }
    [ForeignKey("UserIdFK")]
    public Guid UserId { get; set; }
    public TCSUser TCSUser { get; set; }
    [ForeignKey("KeyIdFK")]
    public Guid KeyId { get; set; }
    public SKey SKey { get; set; }
    public string Path { get; set; 

when I am creating the migration I am not getting any errors but when I am updating the database. I am getting an error saying:

Introducing FOREIGN KEY constraint 'FK_Files_Users_SUserUserId' on table 'Files' may cause cycles or multiple cascades paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

The already answer is outdated and not working on entity framework core 6. they removed the HasRequired method.

0 Answers0