我想存储在用户类的项目集合中
但我无法克服这个问题:
System.InvalidOperationException:“无法映射属性“User.ItemsIds”,因为它属于“List”类型,它不是受支持的基本类型或有效的实体类型。显式映射此属性,或使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略它。
我正在使用 ASP.NET Core 2.0 + EFCore
public 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");
}
}
这是类似的问题,但仍然没有“修复”?
森栏
相关分类