entity framework - The type was not mapped -
im trying run simple program according tutorial find. test code:
program.cs:
using system; using system.collections.generic; using system.data.entity; using system.linq; using system.text; using system.threading.tasks; namespace ef5withmysqlcodefirst { class program { static void main(string[] args) { using(var context = new databasecontext()) { var defaultforum = new forum { forumid = 1, name = "default", description="default forum test insertion." }; context.forums.add(defaultforum); context.savechanges(); } console.readkey(); } public class forum { public int forumid { get; set; } public string name { get; set; } public string description { get; set; } } public class databasecontext : dbcontext { public dbset<forum> forums { get; set; } } } }
this web.config:
<?xml version="1.0" encoding="utf-8"?> <configuration> <configsections> <!-- 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=5.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </configsections> <startup> <supportedruntime version="v4.0" sku=".netframework,version=v4.5" /> </startup> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultconnectionfactory> </entityframework> </configuration>
when execute code, in using(var context = new databasecontext()) line, following error:
the type 'ef5withmysqlcodefirst.program+forum' not mapped. check type has not been explicitly excluded using ignore method or notmappedattribute data annotation. verify type defined class, not primitive, nested or generic, , not inherit entityobject.
please ignore name mysql since not trying yet connect mysql work localdb. searched around , can't solution problem yet.
i think it's failing because forum
class nested inside program
class. error message says, entity types can't nested. try moving outside it's top-level class within namespace.
Comments
Post a Comment