数据库优先或模型优先不支持来自DbContext的DbModelBuilder或EDMX。错误引发行context.Business_Type.ToList(); [英] Database First or Model First is not supported DbModelBuilder or EDMX from a DbContext .the error raises on line context.Business_Type.ToList();

查看:80
本文介绍了数据库优先或模型优先不支持来自DbContext的DbModelBuilder或EDMX。错误引发行context.Business_Type.ToList();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用Model(sql server)作为我的MVC项目。如果我想在没有任何断点的情况下推送F5,则会因为第一次调用方法根据上下文查询数据库而引发错误。



错误是:



"不支持创建DbModelBuilder或从使用Database First或Model First创建的DbContext编写EDMX。 EDMX只能从不使用现有DbCompiledModel创建的Code First DbContext中获得。我使用EF.4和
我通过图表更新我的模型。



*但是如果我使用F10 / F11它会成功通过该行,其余的则通过在上下文中查询它的方法与F5一起使用。



问题仅在于第一种调用方法。



    BApp_Entities上下文;



        public RepositoryBusinessType()

        {

            context = new BApp_Entities();

        }


  &NBSP; &NBSP; &NBSP; public IList< Models.Business_Type> GetAll()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return context.Business_Type.ToList();

  &NBSP; &NBSP; &NBSP; }


context是我模型的一个实例,然后我需要进行查询以检索我的数据,例如:context.Business_Type.ToList();



错误引发行context.Business_Type.ToList();


I use Model first(sql server) for my MVC project. If I want to push F5 without any break point it raises an error for for first calling method to query the database base on context.

The error is:

"Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel." I use EF.4 and I update my model through diagram.

*But if I use F10/F11 it passes that line successfully and for the rest methods which query on context it works fine with F5.

The problem is only with the first calling method.

    BApp_Entities context;

        public RepositoryBusinessType()
        {
            context = new BApp_Entities();
        }

        public IList<Models.Business_Type> GetAll()
        {
            return context.Business_Type.ToList();
        }

context is a instance of my model,then I need to make a query to retrieve my data,like:context.Business_Type.ToList();

the error raises on line context.Business_Type.ToList();

推荐答案

嗨David Rikardson,

Hi David Rikardson,

请打开您的模型(Edmx文件)右键单击空位 - >从数据库更新模型 - >选择修改后的表格以在模型中更新。 

Please open your model (Edmx file) right click empty place -> Update Model from database -> choose the modified table to update them in model. 

如果问题仍然存在,请您分享一个简单的示例,通过OneDrive重现问题。

If the issue still exists, could you please share a simple sample to reproduce the issue via OneDrive.

致以最诚挚的问候,

张龙


这篇关于数据库优先或模型优先不支持来自DbContext的DbModelBuilder或EDMX。错误引发行context.Business_Type.ToList();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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