使用代码为第一个ef核心时的对象名称无效

时间:2018-12-22 01:41:33

标签: c# entity-framework-core

当我尝试从EF核心访问我的导航属性之一时出现错误:

  

无效的对象名称“ CoinbaseAccount”。

var userTransaction =  await this.EntityDBSet.Include(x => x.IncomingCoinbaseAccount)
            .FirstOrDefaultAsync(x => x.TransactionOrderId == transactionId);

该表存在于SQL中,名为dbo.CoinbaseAccounts。

modelBuilder.Entity<UserTransaction>(entity =>
{
    entity.HasOne(d => d.IncomingCoinbaseAccount)
        .WithMany(p => p.IncomingUserTransactions)
        .HasForeignKey(d => d.IncomingCoinbaseAccountId)
        .HasConstraintName("FK_UserTransactions_CoinbaseAccounts");
}

modelBuilder.Entity<CoinbaseAccount>(entity =>
{
    entity.Property(e => e.AccountId)
        .IsRequired()
        .HasMaxLength(256);

    entity.Property(e => e.Address)
        .IsRequired()
        .HasMaxLength(256);
}

任何想法如何解决此问题,我正在使用.Net-Core 2.1

0 个答案:

没有答案