GlobalConfiguration不包含配置的定义 [英] GlobalConfiguration does not contain a definition for Configure

查看:1586
本文介绍了GlobalConfiguration不包含配置的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用数据库优先实体框架的ASP.NET MVC站点。



我正在使用在中创建一个新的MVC 5站点> Visual Studio Professional 2013 Update 3 ,然后添加一个 ADO.NET实体数据模型,从其中选择 EF Designer从数据库



之后,我创建一个连接字符串,选择表来生成框架,一切都很好。



但是当我编译我收到这个错误


'MyModel.GlobalConfiguration'不包含
'配置'的定义


这是在 Global.asax.cs 中,错误在这里

  protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}

GlobalConfiguration 自动使用 MyModel 添加的实体框架生成。它当然没有配置方法。

  public partial class GlobalConfiguration 
{
public int ID {get;组; }
public long CurrentUSN {get;组; }
public string DBVersion {get;组; }
public long CurrentFile {get;组; }
}

我按照所有答案在这里 GlobalConfiguration.Configure()不存在于Web API 2和.NET 4.5.1迁移,但没有工作。这是一个略有不同的情况,因为这不是升级,而是一个干净的项目。



所有扩展和NuGet软件包都是最新的。我甚至删除了生成的实体并重新安装了所有的Nu​​Get软件包,看看是否有帮助,但没有运气。



任何建议?

解决方案

看起来像生成的代码有一些命名空间冲突。对于这个变化,我相当疲倦,但是一切都到目前为止。



显然 GlobalConfiguration 是指 MyModel.GlobalConfiguration



但是它真的在寻找 System.Web.Http.GlobalConfiguration



我切换了这一切,一切正常。什么麻烦

  protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}


I'm attempting to create an ASP.NET MVC site that uses Database First Entity Framework.

I'm using creating a new MVC 5 site in Visual Studio Professional 2013 Update 3, then adding an ADO.NET Entity Data Model from which I choose EF Designer from database.

After that, I create a connection string, select the tables to generate the framework, and all is well.

However when I compile it, I receive this error

'MyModel.GlobalConfiguration' does not contain a definition for 'Configure'

This is in Global.asax.cs and errors here

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

GlobalConfiguration is automatically generated with the added entity framework for MyModel. It certainly doesn't have a Configure method.

public partial class GlobalConfiguration
{
    public int ID { get; set; }
    public long CurrentUSN { get; set; }
    public string DBVersion { get; set; }
    public long CurrentFile { get; set; }
}

I followed all of the answers here GlobalConfiguration.Configure() not present after Web API 2 and .NET 4.5.1 migration but none worked. It's a slightly different situation as this isn't an upgrade but is instead a clean project.

All Extensions and NuGet packages are up to date. I've even deleted the generated entity and reinstalled all NuGet packages to see if that helped, but no luck.

Any suggestions?

解决方案

It looks like there is some sort of namespace conflict with the generated code. I'm fairly weary about this change, but everything has worked thus far.

Apparently GlobalConfiguration refers to MyModel.GlobalConfiguration.

However it's really looking for System.Web.Http.GlobalConfiguration

I switched this and all is working. What a hassle

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

这篇关于GlobalConfiguration不包含配置的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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