c# - Database First with POCOs -


i new entity framework, , trying work pocos. of tutorials seem database first generated code or code first pocos. there not many (though there few) deal database first pocos.

my setup: trying use ef in existing project bit large. question, have attempted following setup.

i have project containing single edmx model, connecting single table on local db. next, copied generated code model.designer.cs .cs file in project. set code generation strategy none. create context class below.

public class localdb : objectcontext {     public const string connectionstring = "name=localentities";     public const string containername = "localentities";      public objectset<product_listing> openlist;      public localdb() :  base(connectionstring, containername)      {         openlist = createobjectset<product_listing>(); //invalidoperationexception!!     } } 

problem: when hit constructor, following exception:

invalidoperationexception.“mapping , metadata information not found entitytype 'efftrial.localaccess.product_listing.”

i’d grateful help. book have (by lerman) related ef-4, code on vs 2010, , .net 4 supports ef-6, think. mentioned above, new, not set on versions long can without .net 4.5.

save trouble :

http://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838

entityframework reverse poco generator

or

http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d

entity framework power tools beta 4

reverse engineer code first - generates poco classes, derived dbcontext , code first mapping existing database.

===========================================

run before leave evening..and check screen saver settings. (aka, take while, esp "power tools" one.

===========================================

here northwind "customer" example. perhaps can map table.

namespace northwindydatalayer.models {     [serializable]     public partial class customer     {         public customer()         {          }          public string customerid { get; set; }         public string companyname { get; set; }         public string contactname { get; set; }         public string contacttitle { get; set; }         public string address { get; set; }         public string city { get; set; }         public string region { get; set; }         public string postalcode { get; set; }         public string country { get; set; }         public string phone { get; set; }         public string fax { get; set; }      } }    using system.data.entity; using system.data.entity.infrastructure; namespace northwindydatalayer.models {     public partial class windycontext : dbcontext     {         static windycontext()         {             //database.setinitializer<windycontext>(null);         }          public windycontext()             : base("name=northwindcontext")         {         }          public dbset<customer> customers { get; set; }           protected override void onmodelcreating(dbmodelbuilder modelbuilder)         {             modelbuilder.configurations.add(new customermap());         }     } }     using system.componentmodel.dataannotations.schema; using system.data.entity.modelconfiguration;  namespace northwindydatalayer.models.mapping {     public class customermap : entitytypeconfiguration<customer>     {         public customermap()         {             // primary key             this.haskey(t => t.customerid);              // properties             this.property(t => t.customerid)                 .isrequired()                 .isfixedlength()                 .hasmaxlength(5);              this.property(t => t.companyname)                 .isrequired()                 .hasmaxlength(40);              this.property(t => t.contactname)                 .hasmaxlength(30);              this.property(t => t.contacttitle)                 .hasmaxlength(30);              this.property(t => t.address)                 .hasmaxlength(60);              this.property(t => t.city)                 .hasmaxlength(15);              this.property(t => t.region)                 .hasmaxlength(15);              this.property(t => t.postalcode)                 .hasmaxlength(10);              this.property(t => t.country)                 .hasmaxlength(15);              this.property(t => t.phone)                 .hasmaxlength(24);              this.property(t => t.fax)                 .hasmaxlength(24);              // table & column mappings             this.totable("customers");             this.property(t => t.customerid).hascolumnname("customerid");             this.property(t => t.companyname).hascolumnname("companyname");             this.property(t => t.contactname).hascolumnname("contactname");             this.property(t => t.contacttitle).hascolumnname("contacttitle");             this.property(t => t.address).hascolumnname("address");             this.property(t => t.city).hascolumnname("city");             this.property(t => t.region).hascolumnname("region");             this.property(t => t.postalcode).hascolumnname("postalcode");             this.property(t => t.country).hascolumnname("country");             this.property(t => t.phone).hascolumnname("phone");             this.property(t => t.fax).hascolumnname("fax");         }     } } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -