ASP.NET MVC3 EF model Inheritance Cannot implicitly convert type

reginakabul

New Member
I am sure i am just missing some pretty basic here, but i can't seem to figur it out.. maybe because its been a while since i have been on the .NET platform.Anyway, I have this database structure i the ASP.NET MVC3 framework where i have "Coruse", "Tool" and "ToolADL"(Inheritance from Tool). A "Course" can have one-or-more "Tools" where one of the "Tool"-types is "ToolADL".Models/Course.cs:\[code\]public class Course { [Key] public int CourseID { get; set; } [Required(ErrorMessage = "{0} er p?kr?vet")] [Display(Name = "V?rkt?j")] public virtual ICollection<Tool> Tools { get; set; }}\[/code\]Models/Tool.cs:\[code\]public abstract class Tool { public Tool(){ Priority = 0; } [Key] public int ToolID { get; set; } [Required] public int CourseID { get; set; } [Required] public int Priority { get; set; }}\[/code\]Models/ToolADL.cs:\[code\]public class ToolADL : Tool { [Required] public string Image { get; set; }}\[/code\]aaand the Models/ProjectContext:\[code\]public class ProjectContext : DbContext { // Course context public DbSet<Course> Courses { get; set; } // Tools public DbSet<Tool> Tools { get; set; } // ToolADL public DbSet<ToolADL> ToolADLs { get; set; }}\[/code\]Now when i try to create the controller and connect to DbContext and the Model to it so the entity framwork can do its magic, I get the following error in the ToolADL controller Details function (and others) where time i use "find()":ToolADLController.Details(int):\[code\]private ProjectContext db = new ProjectContext();public ViewResult Details(int id){ ToolADL tooladl = db.Tools.Find(id); return View(tooladl);}\[/code\]\[quote\] Error 1 Cannot implicitly convert type 'Project.Models.Tool' to 'caREhab_community.Models.ToolADL'. An explicit conversion exists (are you missing a cast?) C:\Users\Thor\Documents\Visual Studio 2010\Projects\Project\Project\Project\ToolADLController.cs 29 31 Project\[/quote\](I changed the name of the orginal project to "Project")I simply cannot figur out what I am doing wrong, Is it wrong types, some really basic about Inheritance i left out or something else?Hope some kind soul can tell me why I am an idiot and can't figure this out :)
 
Back
Top