4

我有两个实体:配方和成分。

实体:

public class Ingredient
{
    public int IngredientId{get;set;}
    public string Name {get;set;}
    public virtual ICollection<Recipe> Recipies {get;set;}
}

public class Recipe
{
    public int RecipeId{get;set;}
    public string Name {get;set;}
    public virtual ICollection<Ingredient> Ingredients {get;set;}
}

我的两个实体映射到我们数据库中“Web”模式中的各自表:

ToTable( "Recipe", "Web" );
ToTable( "Ingredient", "Web" );

...一切正常。唯一的问题是生成的多对多表是在“dbo”模式中创建的。

dbo.RecipeIngredients

如果不定义 Fluent API 中的关系,有没有办法将“Web”指定为用于多对多表的表模式?

4

1 回答 1

1

不可以。数据注释仅支持映射功能的基本子集。如果您想拥有完整的代码优先映射功能集,您必须使用 Fluent API(这也是定义映射的更简洁的方式)。定义与联结表相关的任何内容都被视为高级映射功能,目前仅在 Fluent API 中可用。

于 2012-07-03T14:44:10.203 回答