在实体框架中设置不同模式的导航属性

时间:2013-05-26 10:02:54

标签: c# sql-server entity-framework entity-framework-5

我使用实体框架5在C#中编码,我有一个模型凭证,如下所示:

  public class Voucher
    {
        public int Id { get; set; }

        public int AppId { get; set; }

        public virtual App {get; set;}

        public int? TradeMemberId { get; set; }

        public int FiscalPeriodId { get; set; }
     }

我已将此模型配置为:

ToTable("Voucher", "acc");

因此它被映射到:

  

[ACC]。[凭证]

我的App属性来自同一个数据库但在另一个模式中:

  

[PRF] [应用]

现在,当ef尝试查询并填充App导航属性时,它无法在acc schema中找到它。我可以将此属性标记为prf schema,就像我们对模型一样吗?感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

如果使用数据注释正确定义架构。 EF应该照顾好这个,我之前做过这件事并且从未遇到过任何问题。

[Table("Voucher", Schema = "acc")]
 public class Voucher {...}

and 

[Table("App", Schema = "prf")]
public class App{...}