GlobalConfiguration不包含Configure的定义

时间:2021-09-11 16:57:36

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

我正在尝试创建一个使用Database First Entity Framework的ASP.NET MVC站点。

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.

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

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'

'MyModel.GlobalConfiguration'不包含'Configure'的定义

This is in Global.asax.cs and errors here

这是在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 is automatically generated with the added entity framework for MyModel. It certainly doesn't have a Configure method.

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

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.

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

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.

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

Any suggestions?

有什么建议么?

3 个解决方案

#1


18  

  1. Open the Package Manager Console for the Project with the error.
  2. 使用错误打开项目的程序包管理器控制台。
  3. Type in Install-Package Microsoft.AspNet.WebApi.WebHost and hit Enter.
  4. 键入Install-Package Microsoft.AspNet.WebApi.WebHost并按Enter键。
  5. Rebuild your Project.
  6. 重建您的项目。

#2


3  

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.

显然,GlobalConfiguration指的是MyModel.GlobalConfiguration。

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

但它确实在寻找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);
}

#3


1  

1 - Make sure the files in your Team Explorer, if perform checkin;

1 - 确保团队资源管理器中的文件,如果执行checkin;

2 - Check for old files in "packages" concerning the dll WebAPI such as the folder "Microsoft.AspNet.WebApi.WebHost.5.2.3" folder, if there are clear;

2 - 检查有关dll WebAPI的“软件包”中的旧文件,如文件夹“Microsoft.AspNet.WebApi.WebHost.5.2.3”文件夹,如果有明文;

3 - After leaving everything clean install the project;

3 - 将所有东西都干净后安装项目;

Good luck!!!!!

祝你好运!!!!!

#1


18  

  1. Open the Package Manager Console for the Project with the error.
  2. 使用错误打开项目的程序包管理器控制台。
  3. Type in Install-Package Microsoft.AspNet.WebApi.WebHost and hit Enter.
  4. 键入Install-Package Microsoft.AspNet.WebApi.WebHost并按Enter键。
  5. Rebuild your Project.
  6. 重建您的项目。

#2


3  

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.

显然,GlobalConfiguration指的是MyModel.GlobalConfiguration。

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

但它确实在寻找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);
}

#3


1  

1 - Make sure the files in your Team Explorer, if perform checkin;

1 - 确保团队资源管理器中的文件,如果执行checkin;

2 - Check for old files in "packages" concerning the dll WebAPI such as the folder "Microsoft.AspNet.WebApi.WebHost.5.2.3" folder, if there are clear;

2 - 检查有关dll WebAPI的“软件包”中的旧文件,如文件夹“Microsoft.AspNet.WebApi.WebHost.5.2.3”文件夹,如果有明文;

3 - After leaving everything clean install the project;

3 - 将所有东西都干净后安装项目;

Good luck!!!!!

祝你好运!!!!!