Asp.net cannot get metadata

Hi, I have a problem with MVC to make the controller even after reading the prompts. adding a constructor to DbContext, removing a broken one, changing providerName = "System.Data.SqlClient", etc.

my model class is as follows:

public class RecruiterModel { public string CompanyName { get; set; } public string Website { get; set; } public string CompanySize { get; set; } public string LinkedInCompanyURL { get; set; } public string LinkedInID { get; set; } public string Specialities { get; set; } public string Category { get; set; } public string Location { get; set; } public int ContactPhone { get; set; } public string ContactEmail { get; set; } } public class RecruiterDBContext : DbContext { public DbSet<RecruiterModel> Recruiters { get; set; } } 

and my web.configString connection looks like this:

 <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> <add name="RecruiterDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Recruiters.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> 

any advice?

+1
asp.net-mvc-3
Jul 22 '13 at 12:54 on
source share
2 answers

Add the following Recruiter class property to you:

 public string Id { get; set; } 

Or apply the Key attribute to one of the existing properties. For example:

 [Key] public string CompanyName { get; set; } 

on MSDN, you have the Code First Conventions theme:

Primary key convention

Code First indicates that the property is the primary key if the property on the class is called "ID" (case insensitive), or the name of the class is "ID". If the property type of the primary key is numeric or GUID, this will be configured as an identifier column.

 public class Department { // Primary key public int DepartmentID { get; set; } . . . } 

This Code First DataAnnotations article has the following link to this topic:

Key

Entity Framework relies on every key-value object (aka EntityKey) that it uses to track objects. One of the conventions for this code is primarily dependent on how it implies which property is the key in each of the first code classes. This is a convention for finding a property with the name "Id" or one that combines the class name and "Id", such as "BlogId" . In addition to using EFs, the EntityKey property will appear in the primary key column in the database.

0
Jul 22 '13 at 13:35
source share

I found a solution to create a controller class: In the model class, I added

using System.ComponentModel.DataAnnotations;

public class RecruiterModel {[Key] public string Id {get; set;

then on web.config I commented the whole

connectionStrings tag

Then I created a controller, but it worked.

thanks to guest from Alex Filipovici and Young Yang - MSFT: http://forums.asp.net/t/1888573.aspx/1?Unable+to+retrieve+metadata+for+when+trying+to+create+a+controller

although it works, but on the Solution Explorer tab in App_Data I don't see the db ... hmm file is another problem.

0
Jul 24 '13 at 8:43
source share



All Articles