New WEBAPI Project
Create a new model
?
Installing the Entity Framework
To add a connection string
- Go to the bottom of the <configuration> node in Web. config add
- Edit in Word, not too good to render the code of Things, directly, forgive me.
Add ProductContext.cs Class
Add Productcontroller Controller
- Get
- Post
- Put
- 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
- Open Package Management console
- alt + N + O
- pm> enable-migrations Span style= "font-size:10pt" >
- start migration
- 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.
- pm> add-migration xlzf Span style= "font-size:10pt" >
- XLZF is my custom
- 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 ()
- Pm> Update-database
- Literally, to change the database to go ~
???? At present, the understanding of this block is limited to operations, to be understood later.
API Helper
- Ctrl+f5 Run
Back to the front to see.
WEBAPI Test
- Test tools:
- Get:
- Post
Set Header
Set the JSON for the submission
Results get a bit:
- Delete
The URL followed by an ID is OK
- Put and Post are similar:
Get a look:
C # Webapi Xiao Kee