C # Webapi Xiao Kee

Source: Internet
Author: User

New WEBAPI Project

Create a new model

?

Installing the Entity Framework

To add a connection string

    1. Go to the bottom of the <configuration> node in Web. config add
    2. Edit in Word, not too good to render the code of Things, directly, forgive me.

Add ProductContext.cs Class

Add Productcontroller Controller

    1. Get
    2. Post
    3. Put
    4. Delete

Code First:

I understand it myself:

Code first is that entities are established in the code, creating databases and tables through the entity Framework and the specified connection string. Understand relatively superficial, forgive me.

Description

  1. Open Package Management console
    1. alt + N + O
  2. pm> enable-migrations Span style= "font-size:10pt" >
    1. start migration
    2. This time, you'll find one more. Migrations folder contains Configuration.cs

      < Span style= "font-family: Microsoft Jacob Black; Font-size:10pt "> You can add code to the seed method:

      There will be data when this is migrated, custom.

  3. pm> add-migration xlzf Span style= "font-size:10pt" >
    1. XLZF is my custom
    2. When you're done, you'll find one more class file: Time + custom string

      < Span style= "font-family: Microsoft Jacob Black; Font-size:10pt ">

      you can see that. , this has generated a number of table structures.

      There are two ways: createtable (), Droptable ()

  4. Pm> Update-database
    1. Literally, to change the database to go ~

???? At present, the understanding of this block is limited to operations, to be understood later.

API Helper

    1. Ctrl+f5 Run

      Back to the front to see.

WEBAPI Test

    1. Test tools:

  1. Get:

  2. Post

    Set Header

    Set the JSON for the submission

    Results get a bit:

  3. Delete

    The URL followed by an ID is OK

  4. Put and Post are similar:

    Get a look:

C # Webapi Xiao Kee

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.