第一混合模型第一和code [英] Mixing Model first and Code first

查看:91
本文介绍了第一混合模型第一和code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们创建使用模型第一种方法的Web应用程序。一个新的开发进入了该项目,并使用code第一种方法(使用一个数据库文件)中创建新的自定义模式。在

We created a web application using the model first approach. A new developer came into the project and created a new custom model using the code first approach (using a database file). The

下面是code第一个数据库环境。

Here is the code first database context.

namespace WVITDB.DAL
{
public class DashboardContext : DbContext
{
    public DbSet<CTOReview> CTOReviews { get; set; }
    public DbSet<Concept> Concepts { get; set; }

    //public DashboardContext()
    //    : base("name=DashboardContext")
    //{

    //}


  //  protected override void OnModelCreating(DbModelBuilder modelBuilder)
   // {
   //     //modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
   // }
}
}

下面的控制器方法抛出一个错误找不到'WVITDB.Models.FavoriteProject。概念模型类型和引用原始数据库模型。我们不知道为什么(或如何),它正在调用。

The following controller method throws an error Could not find the conceptual model type for 'WVITDB.Models.FavoriteProject'. and refers to the original database model. We are not sure why (or how) it is calling that.

  public ViewResult Index()
        {
            var d = db.Concepts.ToList(); //Throws error here
            return View("Index",d);
        }

当DashboardContextclass被实例化的错误都显示为两个DBset属性。

When the DashboardContextclass is instantiated the error are shows up for both of the DBset properties.

时有一个原因控制器调用错误的数据库?

Is there are a reason why the controller calling the wrong database?

编辑:

FavoriteProject是在不同的上下文(我们的主要数据模型)并没有涉及到新的自定义模式。

FavoriteProject is in a different context (our main data model) and not related to the new custom model.

推荐答案

找到了答案,这也许不是你想要的,虽然听到的:

Found an answer, it maybe not what you want to hear though:

<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/d2a07542-cb33-48ba-86ed-4fdc70fb3f1a\" rel=\"nofollow\">http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/d2a07542-cb33-48ba-86ed-4fdc70fb3f1a

如果你使用的是默认code一代的EDMX文件,然后将生成的类包含一系列属性来帮助EF找到用于每个实体类型的类。EF目前有一个限制,即POCO类可以'T从包含与EF属性类的程序集加载。(简短的回答是否定的,你的类必须在单独的项目)。

"If you are using the default code generation for the EDMX file then the generated classes contain a series of attributes to help EF find which class to use for each entity type. EF currently has a restriction that POCO classes can't be loaded from an assembly that contains classes with the EF attributes. (Short answer is no, your classes need to be in separate projects).

这是一个有些人为的限制,一些我们知道的是痛苦的,会尝试在未来删除。

This is a somewhat artificial restriction and something that we realize is painful and will try and remove in the future."

所以,解决方法是将这些类分成两个不同的组件。

So the workaround would be to split the classes into two different assemblies.

这篇关于第一混合模型第一和code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆