[英]The property 'Property Name' could not be mapped, because it is of type 'object' which is not a supported primitive type or a valid entity type
I am trying to make a table that has 2 one to many relatishops attached to it.我正在尝试制作一张附有 2 个一对多关联商店的表格。
After some tries I fixed what I could and I am stuck at that error.经过一些尝试,我修复了我可以修复的问题,但我被困在了那个错误中。
The property 'Property Name' could not be mapped, because it is of type 'object' which is not a supported primitive type or a valid entity type.无法映射属性“属性名称”,因为它属于“对象”类型,不是受支持的原始类型或有效的实体类型。
DbContext class for fluentAPI DbContext class 用于fluentAPI
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Account> Accounts { get; set; }
public DbSet<Transaction> Transactions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Transaction>()
.HasOne(p => p.Receiver)
.WithMany(t => t.ReceiveTransactions)
.HasForeignKey(m => m.ReceiverID)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Transaction>()
.HasOne(p => p.Sender)
.WithMany(t => t.SendTransactions)
.HasForeignKey(m => m.SenderID)
.OnDelete(DeleteBehavior.Restrict);
}
}
And here are the rest of the classes这里是类的 rest
User Class用户 Class
public class ApplicationUser : IdentityUser
{
public ICollection<Transaction> SendTransactions { get; set; }
public ICollection<Transaction> ReceiveTransactions { get; set; }
public Account Account { get; set; }
public ApplicationUser()
{
}
}
Transaction交易
public class Transaction
{
[Key]
public String TransactionID { get; set; }
public String SenderID { get; set; }
public String ReceiverID { get; set; }
[DataType(DataType.DateTime)]
public DateTime Date { get; set; }
public String Currency { get; set; }
public float Amount { get; set; }
[ForeignKey("SenderID")]
public ApplicationUser Sender { get; set; }
[ForeignKey("ReceiverID")]
public ApplicationUser Receiver { get; set; }
public object ReceiverId { get; internal set; }
public Transaction(String TransactionID, String SenderID, String ReceiverID, DateTime Date, String Currency, float Amount)
{
this.TransactionID = TransactionID;
this.SenderID = SenderID;
this.ReceiverID = ReceiverID;
this.Date = Date;
this.Currency = Currency;
this.Amount = Amount;
}
}
public object ReceiverId { get; internal set; }
This property is causing the error, because it is not a type that entity framework recognizes for mapping.此属性导致错误,因为它不是实体框架识别用于映射的类型。 Either change the data type to a primitive like int or string, or remove the property.
将数据类型更改为 int 或 string 等原始数据类型,或删除该属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.