Sunday, January 7, 2018

Web API (Part 2) Working with Database using entity framework

Web API - Working with Database:


In this tutorial, we will learn about how to use database and entity framework (.Net framework 3.5)


  • We alread have created Web API in Web API (Part 1)
  • In this section, we will create a class library, a sql database and table and add Ado.net entity data model.
Creating Database first:


  • Let's create a test database and using below script, create a Products table as below:
       


Adding a class library project in the solution:


  • Add a class library and name it as "ProductsDataAccess"
       


  • Add one ADO.NET Entity Data Model
       




  • Choose Model content
           
  • Choose data connection and then specify datasource
         

         



  • Set connection properties and test connection.
          
  • This is how the edmx file will look like
        


Important: Since we are using .net framework 3.5, we do need to "Add Code generation Item" by right clicking the entity "PRODUCT" as shown above.


Please follow "Web API (Part 2 Continued) Working with Database using entity framework" next.





No comments:

Post a Comment

SQL INTERVIEW QUESTIONS (SCENARIO BASED) - Part 1

FINDING Second Highest Salary in SQL CREATE TABLE #EMP ( NAME NVARCHAR ( 100 ), SALARY BIGINT ) INSERT INTO #EMP VALUES (...