c# - Handmade POCO with Entity Framework 6? -


i'm looking using ef 6 upcoming small project doing @ large organization. having poco business objects essential me, of options can find how poco ef seem rely on auto-generating tools try map entire database structure poco objects. have many databases, hundreds of tables, , hundreds of views, , i'm looking use few of these tables time being (and 1 project hope use small subset of them).

additionally don't want map out many foreign properties or of normal properties these tables store. i'd make these poco objects hand , connect them ef , let mapping - i'd still able use edmx file , not have make own objectcontext, if possible.

i feel though has dead simple, can't find resources on it! if can point me in right direction helpful.

entity framework has code first aspect can map existing tables well. allows use pocos represent tables. can create mapping classes allow separate pocos database mapping logic.

you can specify if there different naming of table column poco. if there no difference between 2 however, can omit it.

using projectname.models; using system; using system.collections.generic; using system.data.entity.modelconfiguration; using system.linq; using system.text; using system.threading.tasks;  public class profilemapping : entitytypeconfiguration<profile> {     public profilemapping()     {         // primary key         this.haskey(t => t.id);          // map poco name column name         this.property(t => t.firstname)             .hascolumnname("first_name")             .hasmaxlength("256");           // table mapping         this.totable("profiles");          // relationships         this.hasrequired(t => t.roles);     } } 

using dbcontext can register these mappings.

i recommend using entity framework power tools generate dbcontext existing database.

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


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -