EF Poco Create for a specific table

You can create a class POCO

for one selected table in the entity structure.

There are several tools that do this, but they generate for the whole table,

The main reason I am asking is to create a class POCO

for a separate table and add attributes to it manually and all I have to do is attach it to DbContext

as a property :).

Like for example with Package-manager they do it to add migration

generate-poco TableName FileName.cs

      

+3


source to share


2 answers


You can use the ADO.Net wizard to generate POCO classes for you from the database. The wizard will generate one incomplete class for the table with properties matching your field names. This is what I have done in the past when I wanted to add a new large table to an existing code context.

  • Add-> New Item -> ADO.Net Entity Data Model
  • Move the generated POCO classes to a different folder (and edit the namespace)
  • Remove the rest of the extra stuff (Ieedmx file and generated context)
  • Add DBSet to 'your' DBContext


If you are using EF migrations

  1. add-in migration
  2. updating the database,
+4


source


There are many visual studio extensions for this. EF 4.x POCO Entity Generator for C # Free (try this and you only need to map the table)



+1


source







All Articles