美文网首页
WebApi & EntityFramework with PO

WebApi & EntityFramework with PO

作者: bin_guo | 来源:发表于2017-05-31 05:15 被阅读0次

    <h3>Create two projects</h3>

    1. Creating two projects in one Solution, which including a SQL Server Project, and a Web Api Project.


      Two Project

    <h3>SQL Server Project</h3>

    1. Install <code>EntityFramework</code>. from NuGet Package Management, and <code>Entity Framework Reverse POCO</code> from Extension and Updates in the menu of Tools.


      From NuGet
      From Extension and Updates
    2. Create a database from your SSMS(SQL Server Management Studio)


      Create Empty Database
    3. Import the Database you just created to the SQL Server Project.


      Import to SQL Server Project
    4. Create three tables, Student.sql, Course.sql, and StudentCourse.sql. Because student to course is the relationship of many-to-many. Here we should add a cross table between them, that is StudentCourse.sql.


      Student.sql
      Course.sql
      StudentCourse.sql
    5. Create Foreign Key for both of StudentId and CourseId columns.


      ForeignKey
    6. Right-Click the SQL Server Project, and then Publish to the database, and don't forget to switch the platform version to appropriate one.


      Publish
      Target Platform Version

    <h3>Web API Project</h3>

    1. Create a POCO file, that actually is the <code>context</code> file.


      XXXContext.tt
    2. Edit configuration file from your Context file.


      XXXContext File
    1. Insert <code><connectionString> <add ...> </connectionString></code> to the <code>.Web.config</code> file.


      <connectionString>
    2. In the folder of XXXContext.cs, find the constructor method of XXXContect class, add line inside of it.
      <code>base.Configuration.ProxyCreationEnabled = false;</code>


      Unable the ProxyCreationEnabled property

    <h3>All Set!</h3>

    相关文章

      网友评论

          本文标题:WebApi & EntityFramework with PO

          本文链接:https://www.haomeiwen.com/subject/lksdfxtx.html