1

最初にエンティティ フレームワーク コードに問題があり、次のようにデータベースに 3 つのテーブルがあります。

CREATE TABLE [Food](
PK [FoodId] [int] NOT NULL,
[FoodName] [varchar](50) NULL)

CREATE TABLE [Fruit](
PK [FruitId] [int] NOT NULL,
[FruitName] [varchar](50) NULL)

CREATE TABLE [FoodFruit](
PK, FK [FoodId] [int] NOT NULL,
PK, FK [FruitId] [int] NOT NULL)

モデルは食品、果物のエンティティのみを生成します。

しかし、Notes などの新しい列 [Notes] を FoodFruit テーブルに追加すると、次のようになります。

CREATE TABLE [FoodFruit](
PK, FK [FoodId] [int] NOT NULL,
PK, FK [FruitId] [int] NOT NULL,
[Notes] [varchar](50) NULL)

モデルは Food、Fruit、FoodFruit エンティティを生成します。

だから、最初のものが FoodFruit エンティティを生成しないのはなぜなのか、私は混乱しています。

4

1 に答える 1

2

That is correct behavior. In the first case your FoodFruit table is just database helper to model many-to-many relationship. EF doesn't need such helper in conceptual model so it hides this table behind directly modeled many-to-many relation. In the second case the table has additional data - it becomes full entity, not just junction table for relationship. EF detects it and map it as a new class.

于 2012-04-05T10:40:07.213 に答える