3

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

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

这是生成的 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”映射列“存款”以获取此 SQL:

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

1 回答 1

0

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

有关按代码映射的继承映射,请参见此处

于 2014-08-15T15:56:50.707 回答