gpt4 book ai didi

c# - 无法使用 Entity Framework 创建 Controller - 运行所选代码生成器时出错 '' 无法检索元数据

转载 作者:行者123 更新时间:2023-12-04 10:13:38 28 4
gpt4 key购买 nike

我正在使用 VS2017。当我尝试使用 Entity Framework 创建“带有 View 的 ASP.NET MVC 5 Controller ”时,出现以下错误:

Error

这是我的模型类,我使用 DbSet<Booking>使用 get set 但仍然收到此错误。

IdentityModels.cs

using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace EventManagment.Models
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<UserData> UserDatas { get; set; }
public DbSet<Booking> Bookings { get; set; }
public DbSet<Flower> Flowers { get; set; }
public DbSet<Equipment> Equipment { get; set; }
public DbSet<Food> Foods { get; set; }
public DbSet<Seating> Seatings { get; set; }
public DbSet<Lighting> Lightings { get; set; }
public DbSet<Venue> Venues { get; set; }
public DbSet<EventType> EventTypes { get; set; }

public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}

public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}

预订.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using EventManagment.Models;
using Microsoft.AspNet.Identity;

namespace EventManagment.Models
{
public class Booking
{
[Key]
public int BookingID { get; set; }

//[Display(Name ="CNIC")]
//public String UCNIC { get; set; }
public String Id { get; set; }

[Display(Name ="Event Type")]
public int EventID { get; set; }

[Display(Name ="No Of Guest")]
public int NoOfGuest { get; set; }

[DataType(DataType.Date)]
[Display(Name ="Booking Date")]
public DateTime BookingDate { get; set; }

[Display(Name ="Equipment Type")]
public int EquipmentID{ get; set; }

[Display(Name = "Flower Plan")]
public int FlowerID { get; set; }

[Display(Name = "Food Type")]
public int FoodID { get; set; }

[Display(Name = "Lighting Plan")]
public int LightingID{ get; set; }

[Display(Name = "Seating Plan")]
public int SeatingID { get; set; }

[Display(Name = "Venue Name")]
public int VenueID { get; set; }

//public UserData UserData { get; set; }
[ForeignKey("Id")]
public ApplicationUser User { get; set; }
public EventType EventType { get; set; }
public Equipment Equipment { get; set; }
public Flower Flower { get; set; }
public Food Food { get; set; }
public Lighting Lighting { get; set; }
public Seating Seating { get; set; }
public Venue Venue { get; set; }
}
}
web.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-EventManagment-20200322091502.mdf;Initial Catalog=aspnet-EventManagment-20200322091502;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Syncfusion.Licensing" publicKeyToken="632609b4d040f6b4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-17.4460.0.55" newVersion="17.4460.0.55" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

任何想法出了什么问题?我已经尝试了在 Google 上返回的所有内容。

最佳答案

将 web.config 文件中的更改更改为
数据源=.\MSSQLLocalDB;

关于c# - 无法使用 Entity Framework 创建 Controller - 运行所选代码生成器时出错 '' 无法检索元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61192455/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com