3

PurchaseCredit に挿入しようとすると、次のエラーが表示されます。

SQL ロジック エラーまたは不足しているデータベースの外部キーの不一致 - "Deposit" を参照する "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」から「Deposit」列をマップして、このSQLを取得するにはどうすればよいですか。

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

1 に答える 1