1

In my ASP.NET in the application I use Identity for authorization and registration. I plan to add a small chat, to do this, define the next class for the message

[Table("Messages", Schema = "dbo")]
public class Message
{
    [Key]
    public int Id { get; set; }
    public string Text { get; set; }
    public DateTime SendingTime { get; set; }
    [MaxLength(128),ForeignKey("User")]
    public virtual string SenderID { get; set; }
    public virtual User User { get; set; }
}

User class

public class User : IdentityUser
{
}

In the database, the structure of the table with messages looks like this

Id INT PRIMARY KEY,
SenderId NVARCHAR(128),
CONSTRAINT FK_Messages_To_Users FOREIGN KEY (SenderId) REFERENCES AspNetUsers (Id) ON DELETE CASCADE ,
Text NVARCHAR(1000) NOT NULL,
SendingTime Datetime

When I try to write a message to the database, I get the following error

OnlineChat.DataAccessLayer.Chat.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
OnlineChat.DataAccessLayer.Chat.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined. 
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.

What is the mistake? What did I miss?

pijio
  • 41
  • 5

0 Answers0