Impossible de créer un contrôleur avec la structure Entity - Impossible de récupérer les métadonnées
Je suis en utilisant VS2013
Lorsque j'essaie de créer un "MVC 5 Contrôleur avec des vues à l'aide de entity Framework" j'obtiens l'erreur suivante:
there was an error running the selected code generator ''Unable to retrieve metadata for WebApplication.Domain.Entities.Product'.'
EFDbContext.cs
using System.Data.Entity;
using WebApplication.Domain.Entities;
namespace WebApplication.Domain.Concrete
{
public class EFDbContext : DbContext
{
public DbSet<Product> Products;
}
}
Produit.cs
using System.ComponentModel.DataAnnotations;
namespace WebApplication.Domain.Entities
{
public class Product
{
[Key]
public int ProductID { get; set; }
[Required]
public string Title { get; set; }
}
}
Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<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="EFDbContext" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=WebApplication;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>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<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>
</configuration>
J'ai une Table appelé "Produits", et il a une définition comme suit:
CREATE TABLE [dbo].[Products] (
[ProductID] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (255) NULL,
PRIMARY KEY CLUSTERED ([ProductID] ASC)
);
Toutes les idées ce qui ne va pas? J'ai essayé tout ce qui est revenue sur Google.
Paquets que j'ai installé:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.0.1" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Unity" version="3.0.1304.1" targetFramework="net45" />
<package id="Unity.Mvc" version="3.0.1304.0" targetFramework="net45" />
<package id="WebActivatorEx" version="2.0.4" targetFramework="net45" />
</packages>
Mon projet peut être trouvé ici: https://github.com/jimmyt1988/WebApplication2
source d'informationauteur Jimmyt1988
Vous devez vous connecter pour publier un commentaire.
Oublié le { get; set; }... toutes les œuvres aujourd'hui #pleurs
Problème est peut-être en raison du manque d'
[NotMapped]
Attribut dans un de la classe du modèle.Que j'ai raté l'attribut et j'ai été la ruse de ma tête.
Veuillez vérifier tous les Modèles sont enregistrés dans le contexte
Exemple:
Vous avez un Modèle comme celui-ci
Vérifier tous les
virtual
instances de Modèle sont inscrits dans un contexte comme çaRé-Essayer après la suppression en dessous de la ligne à partir de votre EFDbContext classe.
Exemple:
Dans mon cas, mais à l'aide de VS 2017, cela s'est produit lorsque j'ai eu toute mon modèle de classes définies à l'intérieur d'un seul .cs fichier. Une fois je me suis séparé de chaque classe dans son propre fichier, le processus de génération terminée correctement.