.Net 교육

8/13(금) 5일차 C#.Net 교육

HYOKYE0NG 2021. 8. 13. 18:14
반응형

.Net 6.0 ->add Scaffole에서 ERROR: design 부분이 누락되었기 때문

  Solution ==> Defendencies - NuGet Package Manager - 'Microsoft.EntityFrameworkCore.Design' Install

 

 

HTML4 vs HTML5

  - Cookie를 쓰느냐 안 쓰느냐(4: 쿠키 사용, 5: 쿠키 사용X)

 

 

 

-----

ASP.NET Core Web API

 

1. Create Console Project

 

2. Create Web-Server Project in Solution(Console 프로젝트 위에 utility를 올림): DB를 하지만 UI를 뺐다고 생각

     - ASP.NET Core Wep API

 

3. Person.cs 파일 생성

global using System.ComponentModel.DataAnnotations;

namespace WebApplication1;
public class Person
{
    [Key] // key annotation(personid를 id로 안 썼기 때문에 key 지정 필요)

    public int PersoinId {  get; set; } = default(int);
    public int Age {  get; set; } = default(int);
    public string Name {  get; set; } = default(string);
    public bool Gender { get; set; } = default(bool);
    public string Telephone {  get; set; } = default(string);
}

 

4. Defendencies - NuGet Package Manager - install

     - Microsoft.EntityFrameworkCore

     - Microsoft.EntityFrameworkCore.Desing

     - Microsoft.EntityFrameworkCore.SqlServer

     - Microsoft.EntityFrameworkCore.Tools

 

5. controller - add - new Scaffold item

     - API Controller with actions, using Entity Framework (data context도 create)

 

6. appsettings.json 파일에서 Database(data context) 이름 간단하게 하기

 

7. Tools - NuGet Package Manager - Package Manager Console: DB create AND update

Add-Migration InitialCreate -context [data context명]  / Update-Database -context [data context명]

 

8. View - SQL Server Object Explorer

dbo.Person - right click - view data: data 볼 수 있음

 

9. Ctrl + F5 -> CRUD operation

GET - data get

POST - insert

PUT - update

DELETE - delete

 

 

 

 

-----

JSON meta data로 코딩 (Network Scaffold)

 

JSON meta data

Web Server에서 JSON meta data 복사 -> console project(client)에 JSON file 생성 후 붙여넣기

   - new item - json searching - json file(swagger.json) create

 

Schema Service

   - client(console project) - right click - service reference(manual) / connect service(cloud) - OpenAPI - json file/language 선택

 

완료화면

 

... - view generated code: SwaggerClint.cs file 나타남 (경로: [client project]-[obj]-SwaggerClient.cs)

 

client project - Program.cs 파일에 아래 코드 추가

SwaggerClient client = new("/*url*/", new HttpClient());
var records = await client.WeatherForecastAsync();
foreach (var r in records)
{
    Console.WriteLine($"{ r.Date }: { r.Summary }");
}

Server - properties - launchSettings.json에서 url 복사
Client - url 붙여넣기

 

Server는 실행시켜놓고 Client는 디버그

Server: 실행중 / Client: Debug - Start New Instance

 

결과

 

 

 

 

-----

gRPC

 

 

.NET에서 gRPC 소개

Kestrel 서버 및 ASP.NET Core 스택을 사용하는 gRPC 서비스에 대해 알아봅니다.

docs.microsoft.com

gRPC: Like WebSocket

 

new project - ASP.NET Core gRPC

program.cs: console file

 

Proto: type system(schema), language independent

   - proto file 수정했을 경우 재컴파일 필수(clean and rebuild)

 

 

 

 

 

-----

Server에 DB 붙히기

Properties - launchSettings.json file에서 port 번호 바꿔주기(Web API와 port가 같기 때문)

 

gRPC의 proto folder COPY -> client-project PASTE (drag & drop)

 

Client Project file edit

 

Client Project - proto file의 namespace 수정

 

Client Project - add - service reference - gRPC

 

rebuild and compile

 

 

solution right click -> properties: solution 중 여러 project 동시 실행

 

 

gRPC는 따라가지 못해서 깍두기가 되어버렸다,,^^ 깍두기는 저녁 메뉴나 찾아야겠다 아몰랑 ~~~

 

 

 

 

 

-----

DB

 

시작 - EF Core

Entity Framework Core에 대한 시작 자습서

docs.microsoft.com

 

 

----

WPF

 

WPF 시작 - EF Core

Entity Framework Core에서 WPF 사용에 대한 시작 자습서

docs.microsoft.com

 

반응형