Receiving error in trying to build my own project through Entity Framework based on MvcMovies project featured in the Microsoft Visual Studio Express tutorial.
After having created the MvcMovies project successfully, I'm trying to create a different project based on the MvcMovies project but with my own variables, changing any MvcMovie variable to my own variables/names (using Sample Project / Sample Model / Sample
Controller).
Three pieces of information are included below...
a. Error received in adding controller
b. Options selected in adding controller
c. Model.cs code
Question:
1. Why am I receiving error about primary key selection in my sample and received no such error in creating the MvcMovies tutorial sample?
2. If creating a key is the (only) problem, how do designate a key in the sample model.cs code?
3. Do you see any other errors that I might be making in trying to move the tutorial example to my own example?
_______
a. Error received in adding controller
Microsoft Visual Web Developer 2010 Express
Unable to retrieve metadata for "Sample_Project.Model". One or more validation errors were detedted during model generation:
-System.Data.Edm.EdmEntityType: : EntityType 'Sample_Model" has no key defined. Define the key for this EntityType.
-System.Data.Edm.EdmEntitySet: EntityType: EntitySet □Sample_Model□ is based on type □Sample_Model□ that has no key defined.
_______
b. Options selected in adding controller
Add Controller
Controller name:
SampleController
Scaffolding options
Template:
Controller with read/write actions and views, using Entity Framework
Model class:
Sample_Model(Sample_Project.Models)
Data context class:
Sample_ModelDBContext (Sample_Project.Models)
Views:
Razor (CSHTML)
_______
c. Model.cs code
using System;
using System.Data.Entity;
namespace Sample_Project.Models
{
public class Sample_Model
{
public int SampleFieldID { get; set; }
public string SampleFieldText { get; set; }
public DateTime SampleFieldDate { get; set; }
public string SampleFieldText02 { get; set; }
public decimal SampleFieldCurrency { get; set; }
}
public class Sample_ModelDBContext : DbContext
{
public DbSet<Sample_Model> Sample_Model { get; set; }
}
}
I simplified the names so that they contained no spaces and it seems to resolved the key error I was receiving.
I think I may have posted this question in wrong section of forum, confusing the term "data scaffolding" with what "Entity Framework" does. Thanks for considering the question.
Dean
Marked as answer by 3v3rhart on Feb 18, 2012 12:32 PM
3v3rhart
Member
159 Points
317 Posts
Entity Framework CRUD creation v primary key in Model.cs
Feb 01, 2012 04:18 PM|LINK
Receiving error in trying to build my own project through Entity Framework based on MvcMovies project featured in the Microsoft Visual Studio Express tutorial.
After having created the MvcMovies project successfully, I'm trying to create a different project based on the MvcMovies project but with my own variables, changing any MvcMovie variable to my own variables/names (using Sample Project / Sample Model / Sample Controller).
Three pieces of information are included below...
a. Error received in adding controller
b. Options selected in adding controller
c. Model.cs code
Question:
1. Why am I receiving error about primary key selection in my sample and received no such error in creating the MvcMovies tutorial sample?
2. If creating a key is the (only) problem, how do designate a key in the sample model.cs code?
3. Do you see any other errors that I might be making in trying to move the tutorial example to my own example?
_______
a. Error received in adding controller
Microsoft Visual Web Developer 2010 Express
Unable to retrieve metadata for "Sample_Project.Model". One or more validation errors were detedted during model generation:
-System.Data.Edm.EdmEntityType: : EntityType 'Sample_Model" has no key defined. Define the key for this EntityType.
-System.Data.Edm.EdmEntitySet: EntityType: EntitySet □Sample_Model□ is based on type □Sample_Model□ that has no key defined.
_______
b. Options selected in adding controller
Add Controller
Controller name:
SampleController
Scaffolding options
Template:
Controller with read/write actions and views, using Entity Framework
Model class:
Sample_Model(Sample_Project.Models)
Data context class:
Sample_ModelDBContext (Sample_Project.Models)
Views:
Razor (CSHTML)
_______
c. Model.cs code
using System;
using System.Data.Entity;
namespace Sample_Project.Models
{
public class Sample_Model
{
public int SampleFieldID { get; set; }
public string SampleFieldText { get; set; }
public DateTime SampleFieldDate { get; set; }
public string SampleFieldText02 { get; set; }
public decimal SampleFieldCurrency { get; set; }
}
public class Sample_ModelDBContext : DbContext
{
public DbSet<Sample_Model> Sample_Model { get; set; }
}
}
3v3rhart
Member
159 Points
317 Posts
Re: Entity Framework CRUD creation v primary key in Model.cs
Feb 18, 2012 12:32 PM|LINK
I simplified the names so that they contained no spaces and it seems to resolved the key error I was receiving.
I think I may have posted this question in wrong section of forum, confusing the term "data scaffolding" with what "Entity Framework" does. Thanks for considering the question.
Dean