我正試圖制作一個有2個一對多關系的表格。
經過一些嘗試,我修復了我能修復的東西,但我被這個錯誤困住了。
屬性'Property Name'無法被映射,因為它的型別是'object',這不是一個被支持的原始型別或有效的物體型別。
用于fluentAPI的DbContext類
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)。
}
}
這里是其余的類
用戶類
用戶類
public class ApplicationUser : IdentityUser >。
{
public ICollection<Transaction> SendTransactions { get; set; }
public ICollection<Transaction> ReceiveTransactions { get; set; }
public Account Account { get; set; }
public ApplicationUser( )
{
}
交易
public class Transaction
{
[]
public String TransactionID { get; set; }
public String SenderID { get; set; }
public String ReceiverID { get; set; }
[]
public DateTime Date { get; set; }
public String Currency { get; set; }
public float Amount { get; set; }
[
uj5u.com熱心網友回復:
public object ReceiverId {get; internal set; }
這個屬性導致了錯誤,因為它不是物體框架所認可的映射型別。要么將資料型別改為int或string這樣的原始型別,要么洗掉該屬性。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/320333.html
標籤:
