1

Fluent によって生成される DDL は、多対多の関係 (つまり、ジャンクション / リンク / ブリッジ テーブル) のテーブルを構成する 2 つの列の PK を作成しないことに気付きました。

たとえば (Fluent ソースの Example.FirstProject から)、

Store <-- many-to-many --> Product

StoreProduct テーブルには、次の 2 つの列があります。

ProductFK, StoreFK

この StoreProduct テーブルは、Fluent の HasManyToMany ステートメントによって暗黙的に生成されます。2つの列をPKとして定義するDDLを生成したいと思います。

これは、Fluent for SQLite によって生成されるものです。

create table StoreProduct 
(ProductFK INT not null, 
StoreFK INT not null, 
constraint FKE9A26716DC700501 foreign key (StoreFK) references "Store", 
constraint FKE9A26716815A48A8 foreign key (ProductFK) references "Product");

私はこれをしたい:

create table StoreProduct 
(ProductFK INT not null, 
StoreFK INT not null, 
constraint FKE9A26716DC700501 foreign key (StoreFK) references "Store", 
constraint FKE9A26716815A48A8 foreign key (ProductFK) references "Product",
PRIMARY KEY(ProductFK, StoreFK));

Fluent でそれは可能ですか (つまり、流暢に指定して、StoreProduct ブリッジ テーブルに ProductFK と StoreFK の両方の PK を持たせる)?

4

1 に答える 1

0

主キーの生成は、StoreProduct を関連付けテーブルとしてではなく、独自の DataClass として実装する場合にのみ実行できます。しかし、そうすれば、多対多ではなく連鎖した多対 1 の関係になることはありません。

于 2012-05-04T12:08:11.510 に答える