Entity Framework 5 - How to generate POCO classes from existing database

前端 未结 2 967
情歌与酒
情歌与酒 2020-12-14 19:39

I am using VS 2012 and EF 5. I have an existing database that I want to create POCO classes from the existing database. I followed the steps to add an ADO.NET Entity Data

2条回答
  •  心在旅途
    2020-12-14 20:30

    The process to do this is pretty streamlined now, it seems. The steps from the accepted answer are now easy to do from the EDMX designer itself. Basically,

    • Generate the model (edmx) from an existing database by adding ADO.NET Entity Data Model to the project (see here for more details),
    • and then

    Open the .edmx file in the Entity Designer.

    Right-click an empty area on the Entity Designer surface and point to Add Code Generation Item.

    In the Add New Item dialog, select Online Templates and type DBContext in the Search Online Templates text box.

    Select the appropriate version for your template (5.0, if you want to target the Entity Framework 5.0).

    Click OK.

    This will do all the work, apparently. The quoted instructions here refer to Online Templates as installing EF 5.x DbContext Fluent Generator is required. If you have it already installed, there is no need to search for it in the Online Templates but in the Installed Templates.

    For more info you can check this page, section "To use the DbContext Generator Template to Generate Object Layer Code".

提交回复
热议问题