Cześć,
tworze sobie model bazy w EFCore (Code-first) i napotkałem się na dziwny problem. Mam taki model dla Usera:
public class User : Entity, IUserBaseDto
{
[Key]
[Required]
public int? UserId { get; set; }
public int? ExternalUserId { get; set; }
[Required]
[JsonIgnore]
public string UserSalt { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string Surname { get; set; }
public bool IsLocked { get; set; }
public virtual ICollection<UserLogin> UserLogin { get; set; }
public virtual ICollection<UserPassword> UserPassword { get; set; }
public virtual ICollection<UserRole> UserRoles { get; set; }
[JsonIgnore]
public List<RefreshToken> RefreshTokens { get; set; }
}
oraz do tego mam kilka modeli dla różnego rodzaju przedmiotów (każdy z nich dziedziczy po modelu "ItemBase"):
public class Engine : ItemBase
{
public Enums.Fuel FuelType { get; set; }
public decimal EngineAmount { get; set; }
public decimal Mileage { get; set; }
public string Number { get; set; }
}
public class ItemBase : Entity
{
[Key]
[Required]
public int? Id { get; set; }
public string Title { get; set; }
public string[] PartNumbers { get; set; }
public decimal Price { get; set; }
public ICollection<User> AddedBy { get; set; }
public ICollection<ItemComment> Comments { get; set; }
public virtual Location Location { get; set; }
public int? LocationId { get; set; }
public int? BrandId { get; set; }
public int? ModelId { get; set; }
public int? TypeId { get; set; }
public int? SubTypeId { get; set; }
public BcDictionaryBase Brand { get; set; }
public BcDictionaryBase Model { get; set; }
public BcDictionaryBase Type { get; set; }
public BcDictionaryBase SubType { get; set; }
}
Niestety, przy takim po odpaleniu migracji do mojej tabeli User
dodawane są FK dla każdego z modeli.
Jak mogę tego uniknąć?