Monday 18 August 2014

Generate POCO Code First from existing database from in .NET ( Entity Framework 6 Tools for Visual Studio 2012 & 2013 )

Code First is best approach when starting your coding first and generate your database from your written code i.e. Plane Old CLR Objects ( POCO ) classes. But there might be a situation, when you want to use your existing database to develop your .net application using it, in that scenario one option is to use .edmx to generate your context and designer view but some people only used to work with pure poco's don't want to get into designer or database directly, so in that case we could visual studio extension/tool at

Entity Framework 6 Tools for Visual Studio 2012 & 2013 , just need to download .msi file and install it in your system.

After installation, to generate poco's from your existing database do following easy steps :

1 ) Right click to your project/project's folder and click add new item 

 2 ) Then select ADO.NET Entity Data Model and click Add


3 ) Where you can see new Model Content type i.e. Code First From Database, select it and click next


4 ) Establish connection with your database


5) Do next , select the tables you want to enter and click finish and finally you will see following kind of result, where Address and User are POCOs from database and Model1.cs is context class.


That's how you can create pure POCOs and context from existing database and use it in code first fashion, so enjoy :)

No comments:

Post a Comment