спасибо заранее. В моей базе данных две сущности - AppUsers и Stores - имеют отношения «многие ко многим», а таблица StoreUser работает как их таблица соединения.
AppUser Entity
public class AppUser: IdentityUser
{
[Required]
[MaxLength(50)]
public string NickName { get; set; }
public bool IsActive { get; set; }
public ICollection<StoreUser> StoreUsers { get; set; }
}
Store Entity
public class Store
{
public int Id { get; set; }
public string CompanyName { get; set; }
............ *//For some reasons, I cannot create navigation property StoreUsers here like AppUser*
}
Присоединение к таблице сущностей
public class StoreUser
{
public string UserId { get; set; }
public AppUser User { get; set; }
public int StoreId { get; set; }
public Store Store { get; set; }
public int Position { get; set; }
}
Контекст базы данных
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<StoreUser>().HasKey(x => new { x.StoreId, x.UserId});
builder.Entity<StoreUser>().HasOne(x => x.User)
.WithMany(y => y.StoreUsers).HasForeignKey(x => x.UserId);
builder.Entity<StoreUser>().HasOne(x => x.Store)
.WithMany() *//As no navigation property specified in Store class, I leave WithMany()'s parameter blank.*
.HasForeignKey(x => x.StoreId);
}
Мой вопрос: поскольку в классе Store нет свойства навигации, как я могу управлять CRUD через сущность Store?
Большое спасибо.