I’m losing performance by not having a relationship through foreign key and just keeping the UserId on a property string?
It is. In fact, you can associate your ApplicationUser normally to any other entity, taking only a few precautions.
In order for the relationship between entities to work, care must be taken to envelop the context with the RoleManager and the UserManager as follows:
UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
In any case, if you feel you are experiencing a lot of performance loss, I suggest you reimplement your ApplicationUser using as key Guid or int:
public class MeuUserComGuid : IdentityUser<Guid, GuidUserLogin, GuidUserRole, GuidUserClaim>
{
public User()
{
Id = Guid.NewGuid();
}
public User(string name) : this() { UserName = name; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
A little vent: a thing that discouraged me in the
Asp.Net Identitywas theUserIdbe aGuidsaved asstring, even if there is no relationship between Products and users, you can create an Info for the Userid column in Products– Tobias Mesquita
Hi, @Tobymosque. If I add
[Index]on top of my Userid property the query will be enhanced or need to do more?– user8356