gpt4 book ai didi

c# - 映射JoinedSubclassMapping

转载 作者:行者123 更新时间:2023-11-30 18:33:11 26 4
gpt4 key购买 nike

当我尝试插入 PurchaseCredit 时出现此错误:

SQL逻辑错误或缺少数据库外键不匹配 - “PurchaseCredit”引用“Deposit”

这是生成的 SQL 的一部分:

create table FinancialDeposit 
(
Id integer primary key autoincrement,
Version BIGINT not null,
DatePayment date,
Total money,
Status INT,
)

create table Deposit
(
FinancialDepositId BIGINT not null unique,
AccountId BIGINT not null,
PersonName varchar(250) not null,
primary key (FinancialDepositId),
constraint FK737CDD9090887321 foreign key (AccountId) references Account,
constraint FinancialDepositFK foreign key (FinancialDepositId) references FinancialDeposit
)

create table PurchaseCredit
(
Id integer primary key autoincrement,
Version BIGINT not null,
PurchaseCode UNIQUEIDENTIFIER not null unique,
DepositId BIGINT,
Total money,
constraint FK737CDB4BFA0E8716 foreign key (DepositId) references Deposit
)

这是 C# 代码的一部分:

public class FinancialDepositMap : ClassMapping<FinancialDeposit>
{
public FinancialDepositMap()
{
Property(x => x.DatePayment, map => map.Column(a => a.SqlType("date")));
Property(x => x.Total);
Property(x => x.Status);
Property(x => x.DatePayment);
Property(x => x.Hash);
}
}

public class DepositMap : JoinedSubclassMapping<Deposit>
{
public DepositMap()
{
ManyToOne(x => x.AccountId, m => m.NotNullable(true));
Property(x => x.PersonName, m => m.NotNullable(true));
}
}

public class PurchaseCreditMap : ClassMapping<PurchaseCredit>
{
public PurchaseCreditMap()
{
Property(x => x.PurchaseCode, map =>
{
map.Unique(true);
map.NotNullable(true);
map.Update(false);
});

ManyToOne(x => x.Deposit);
Property(x => x.Total);
}
}

我如何映射“PurchaseCreditMap”中的“Deposit”列以获取此 SQL:

create table PurchaseCredit 
(
...
constraint FK737CDB4BFA0E8716 foreign key (DepositId) references Deposit (FinancialDepositId)
)

最佳答案

您的映射中没有定义任何键或 ID。

参见 here用于按代码映射中的继承映射

关于c# - 映射JoinedSubclassMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17748943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com