Di seguito è la sottoclasse IdentityUser e un'entità semplice. Come si può fare riferimento a IdentityUser all'interno della classe Entity? Questa applicazione utilizza Entity Framework Core.
ApplicationUser.cs
using Microsoft.AspNetCore.Identity;
namespace MyProject.Models
{
public class ApplicationUser : IdentityUser
{
}
}
Entity.cs
namespace MyProject.Models
{
public class Entity
{
public int EntityId { get; set; }
/* What belongs here to associate to a user? */
}
}
Il modo di convenzione-over-configurazione sarebbe:
public class Entity
{
public int EntityId { get; set; }
public string ApplicationUserId { get; set; }
public ApplicationUser ApplicationUser { get; set; }
}
E il seguente è facoltativo, puoi ometterlo se non hai bisogno di ottenere tutte le Entities
per un utente.
public class ApplicationUser : IdentityUser
{
public ICollection<Entity> Entities { get; set; }
}