[英]Entity Framework 7 Invalid Column Name
我正在為現有數據庫創建EF7映射,但出現“無效的列名”錯誤。 引發錯誤的代碼是:
public class DepositContext : DbContext
{
public DbSet<tblBatch> Batches { get; set; }
public DbSet<tblTransaction> Transactions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<tblBatch>().HasKey(b => b.BatchID);
modelBuilder.Entity<tblTransaction>().HasKey(t => t.TransactionID);
modelBuilder.Entity<tblBatch>().HasMany(b => b.tblTransactions).WithOne().HasForeignKey(t => t.fBatchID);
}
}
public class tblBatch
{
public int BatchID { get; set; }
public int? fDepositID { get; set; }
public Guid BRN { get; set; }
public string BCN { get; set; }
public decimal? BCT { get; set; }
public string BatchFileName { get; set; }
public List<tblTransaction> tblTransactions { get; set; }
}
public class tblTransaction
{
public int TransactionID { get; set; }
public string TRN { get; set; }
public string TransactionStatus { get; set; }
public int fBatchID { get; set; }
public tblBatch tblBatch { get; set; }
}
這將Invalid column name 'tblBatchBatchID1'.
當我使用SQL事件探查器查看發送到數據庫的內容時,它是:
exec sp_executesql N'SELECT [t].[TransactionID], [t].[fBatchID], [t].[TRN], [t].[TransactionStatus], [t].[tblBatchBatchID1]
FROM [tblTransaction] AS [t]
INNER JOIN (
SELECT DISTINCT TOP(1) [b].[BatchID]
FROM [tblBatch] AS [b]
WHERE [b].[BatchID] = @__BatchId_0
) AS [b] ON [t].[fBatchID] = [b].[BatchID]
ORDER BY [b].[BatchID]',N'@__BatchId_0 int',@__BatchId_0=37
有人知道如何解決此問題嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.