I have the following class structure:
public class Revenda
{
[InverseProperty("Revenda")]
public virtual ICollection<UsuarioRevenda> Usuarios { get; set; }
}
public class Empresa
{
[InverseProperty("Empresa")]
public virtual ICollection<UsuarioEmpresa> Usuarios { get; set; }
}
public class Cliente
{
[InverseProperty("Cliente")]
public virtual ICollection<UsuarioCliente> Usuarios { get; set; }
}
I've omitted some properties to not be too long.
The structure consists of Resales containing Business and these contain your clients. Companies are resellers customers got called that way.
However, what I'm showing in the structure is that by class Revenda
has the list of registered Users for Revenda
, in Empresa
has its Users list and Cliente
the same, users.
Soon, then I have:
public class Usuario : IdentityUser {
[Required]
[ForeignKey("Revenda")]
public virtual int RevendaId { get; set; }
public virtual Revenda Revenda { get; set; }
[Required]
[ForeignKey("Empresa")]
public virtual int? EmpresaId { get; set; }
public virtual Empresa Empresa { get; set; }
[Required]
[ForeignKey("Cliente")]
public virtual int? ClienteId { get; set; }
public virtual Cliente Cliente { get; set; }
}
Other user profiles:
public class UsuarioRevenda : Usuario {
[Required]
[ForeignKey("Revenda")]
public override int RevendaId { get; set; }
public override Revenda Revenda { get; set; }
}
public class UsuarioEmpresa : Usuario {
[Required]
[ForeignKey("Empresa")]
public override int? EmpresaId { get; set; }
public override Empresa Empresa { get; set; }
}
public class UsuarioCliente : Usuario {
[Required]
[ForeignKey("Cliente")]
public override int? ClienteId { get; set; }
public override Cliente Cliente { get; set; }
}
Some properties of each class have also been omitted here, such as UsuarioRevenda
, which has a Companies navigation property that it has access to.
Migrations
, for example, can not have a property of type Add-Migration
, because of the Revenda
attribute that points to a property originally declared in class ICollection<UsuarioRevenda>
, property InverseProperty
.
The message is as follows:
Reseller: FromRole: NavigationProperty 'Reseller' is not valid. Type 'UserRevenda' of FromRole 'Reseller_Usuarios_Target' in AssociationType 'Reseller_Users' must exactly match with the type 'User' on which this NavigationProperty is declared on.
All user classes are linked in the same database table and are then automatically