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

前端 未结 2 963
情歌与酒
情歌与酒 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:17

    Use EF 5.x DbContext Fluent Generator

    You can add it from online templates:

    • Generate edmx from existing database
    • Select Add New Item
    • Search online templates for POCO
    • Add EF 5.x DbContext Fluent Generator

    It will add three T4 templates to your project:

    • XXX.Context.tt - context inherited from DbContext
    • XXX.Entities.tt - POCO entities
    • XXX.Mappings.tt - fluent mappings for each entity

    BUT you need to setup path to your edmx data model manually. Each of these templates have line string inputFile = @"$edmxInputFile$";. You need to provide name of your edmx file here:

    string inputFile = @"Northwind.edmx";

提交回复
热议问题