asp.net mvc 4 - MVC4 - Controller Scaffolding, Custom Data context class issue: Unable to retrieve metadata -
when try create controller scaffolding, following error:
unable retrieve metadata 'turkup.models.admin.createcourseviewmodel'. schema specified not valid. errors: mapping of clr type edm ambiguous because multiple clr types match edm type 'coursework'.
here code model:
using system.componentmodel.dataannotations; using system.web.mvc; namespace torkup.models.admin { public class createcourseviewmodel { [hiddeninput(displayvalue = false)] public int id { get; set; } [required] public string title { get; set; } } }
the custom data context class:
using system.data.entity; using system.linq; using torkup.classlibrary; using torkup.classlibrary.admin; using torkup.classlibrary.user; namespace torkup.infrastructure { public class universitydb : dbcontext, iuniversitydatasource { public universitydb() : base("defaultconnection") { } // admin data public dbset<course> courses { get; set; } public dbset<class> classes { get; set; } public dbset<coursework> courseworks { get; set; } public dbset<student> students { get; set; } // user data public dbset<assignment> assignments { get; set; } public dbset<task> tasks { get; set; } // admin data iqueryable<course> iuniversitydatasource.courses { { return courses; } } iqueryable<class> iuniversitydatasource.classes { { return classes; } } iqueryable<coursework> iuniversitydatasource.courseworks { { return courseworks; } } iqueryable<student> iuniversitydatasource.students { { return students; } } // user data iqueryable<assignment> iuniversitydatasource.assignments { { return assignments; } } iqueryable<task> iuniversitydatasource.tasks { { return tasks; } } // save database void iuniversitydatasource.save() { savechanges(); } } }
and class course:
using system.collections.generic; namespace torkup.classlibrary.admin { public class course { public int id { get; set; } public string title { get; set; } public string description { get; set; } public icollection<class> classes { get; set; } public icollection<coursework> courseworks { get; set; } } }
if have error, because in dbcontext
:
// admin data public dbset<course> courses { get; set; } public dbset<class> classes { get; set; } public dbset<coursework> courseworks { get; set; } //you use here coursework class create dbset. when scaffold use createcourseviewmodel. public dbset<student> students { get; set; }
if want use createcourseviewmodel
, have change line above. think put viewmodel
suffix purpose of createcourseviewmodel
wrap classes displaying in view.
Comments
Post a Comment