public class TransactionIdentityModelMapping : ClassMap<TransactionIdentityModel>
{
public TransactionIdentityModelMapping()
{
Table("TransactionIdentities");
Id(x => x.Id);
References(x => x.Transaction);
}
}
public class TransactionModelMapping : ClassMap<TransactionModel>
{
public TransactionModelMapping()
{
Table("Transactions");
Id(x => x.Id);
HasMany(x => x.Identities);
}
}
TransactionIdentityModel.Transaction
的類型爲TransactionModel
。這意味着有一個名爲"TransactionModel_id"
的列。我如何更改此列名稱?指定外鍵列的名稱
我曾嘗試:
References(x => x.Transaction).Column("Transaction_id");
和:
References(x => x.Transaction).ForeignKey("Transaction_id");
和:
References(x => x.Transaction).Column("Transaction_id").ForeignKey("Id").Fetch.Join();
這些都產生了2列,一個我想要的( 「TRANSACTION_ID」)和原始(「TransactionModel_id」)。
我是否還需要對HasMany
做些什麼?
編輯型號:
public class TransactionModel
{
/// <summary>
/// For NHibernate
/// </summary>
protected TransactionModel()
{
}
public static TransactionModel FromId(TransactionIdentityModel tranIdentity)
{
return new TransactionModel
{
Identities = new List<TransactionIdentityModel> { tranIdentity }
};
}
public virtual Guid Id { get; protected set; }
public virtual IList<TransactionIdentityModel> Identities { get; protected set; }
}
public class TransactionIdentityModel
{
public virtual Guid Id { get; protected set; }
public virtual TransactionModel TransactionModel { get; set; }
}
屈服2列,這是,如果我使用地圖生成的SQL: References(x => x.Transaction).Column("Transaction_id").ForeignKey("Id").Fetch.Join();
alter table TransactionIdentities
add constraint Id
foreign key (Transaction_id)
references Transactions
alter table TransactionIdentities
add constraint FK958B77026F5C4B80
foreign key (TransactionModel_id)
references Transactions
沒有工作我結束了兩個,一個叫做「Transaction_id」,一個叫做「TransactionModel_id」。有什麼我需要做的''ClassMap'它有一個'HasMany'鏈接? –
weston
查看編輯問題的'HasMany'方。 – weston
@weston你可以發佈你的類定義'TransactionModel'和'TransactionIdentityModel'請 – CSL