我想存儲(chǔ)在用戶類的項(xiàng)目集合中但我無法克服這個(gè)問題:System.InvalidOperationException:“無法映射屬性“User.ItemsIds”,因?yàn)樗鼘儆凇癓ist”類型,它不是受支持的基本類型或有效的實(shí)體類型。顯式映射此屬性,或使用“[NotMapped]”屬性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略它。我正在使用 ASP.NET Core 2.0 + EFCorepublic class User{ [Key] public Guid Id { get; set; } [ForeignKey("Items")] public virtual List<Guid> ItemsIds{ get; set; } (...)}public class Item{ [Key] public Guid Id { get; set; } public string ItemName { get; set; } public Item(string name) { Id = new Guid(); ItemName = name; }}public class AppContext : DbContext{ public AppContext(DbContextOptions<AppContext> options) : base(options) { Database.SetCommandTimeout(35000); } public DbSet<User> Users { get; set; } public DbSet<Item> Items { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<User>().ToTable("Users"); modelBuilder.Entity<Item>().ToTable("Items"); }}這是類似的問題,但仍然沒有“修復(fù)”?
2 回答

森欄
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
您不能只存儲(chǔ)依賴實(shí)體標(biāo)識(shí)符。
主體實(shí)體User必須收集Item:
public class User
{
[Key]
public Guid Id { get; set; }
public virtual List<Item> Items { get; set; }
// ...
}
- 2 回答
- 0 關(guān)注
- 264 瀏覽
添加回答
舉報(bào)
0/150
提交
取消