我有一個POCO模型,主鍵屬性映射到具有不同名稱的列上。實體框架遷移:PrimaryKey
的模型是這樣的:
public class Transaction
{
public long Id { get; set; }
//....more props
}
因此遷移看起來類似:
CreateTable(
"dbo.dtlTransactions",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intTransactionID"),
//...more cols
})
.PrimaryKey(t => t.Id);
在運行此遷移,但是,我得到:
System.Data .SqlClient.SqlException(0x80131904):列名'Id'在目標表或視圖中不存在 。
它看起來好像在生成sql時沒有使用columnbuilder的name屬性。在遷移的-verbose選項給我這個SQL:
CREATE TABLE [dbo].[dtlTransactions] (
[intTransactionID] [bigint] NOT NULL IDENTITY,
--...other cols
CONSTRAINT [PK_dbo.dtlTransactions] PRIMARY KEY ([Id])
任何想法?這是一個明顯的錯誤?
FWIW,對於TableBuilder中的ForeignKey和Index似乎存在同樣的錯誤。 –