티스토리 뷰
SqlQuery와 ExecuteSql의 차이점을 알아야한다.
SqlQuery
List<WordEntity> wordEntities = context.Database.SqlQuery<WordEntity>($"""
select
word.WordSeq
, word.Spelling
, word.Meaning
, word.NationSeq
from dbo.Word as word with(nolock)
"""
).ToList<WordEntity>();
ExecuteSql & ExecuteSqlAsync
public long SetWord(WordEntity wordEntity)
{
using (var context = new SQLDBContext())
{
return context.Database.ExecuteSql($"""
insert into dbo.Word (
Spelling
, Meaning
, NationSeq
) values (
{wordEntity.Spelling}
, {wordEntity.Meaning}
, 1
)
"""
);
}
}
public async Task<long> SetWord(WordEntity wordEntity)
{
using (var context = new SQLDBContext())
{
return await context.Database.ExecuteSqlAsync($"""
insert into dbo.Word (
Spelling
, Meaning
, NationSeq
) values (
{wordEntity.Spelling}
, {wordEntity.Meaning}
, 1
)
"""
);
}
}
ExecuteSqlRawAsync
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Data;
public async Task<int> SetWord(WordEntity wordEntity)
{
using (var context = new SQLDBContext())
{
var pId = new SqlParameter("@id", SqlDbType.Int);
pId.Direction = ParameterDirection.Output;
string query = "insert into dbo.Word (Spelling, Meaning, NationSeq, Level) values (@p0, @p1, @p2, @p3); set @id = scope_identity();";
await context.Database.ExecuteSqlRawAsync(query, "fff", "ddd", 1, "B2", pId);
var id = (int)pId.Value;
return id;
}
}
728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 표현 언어(expression language)
- 진수 변환
- error-java
- docker
- System.Diagnostics
- 스프링 시큐리티(spring security)
- nl2br
- MainActor
- jsp 오픈 소스
- REST API
- jstl(java standard tag library)
- 문자 자르기
- 인텔리제이(intellij)
- 스프링 시큐리티(spring security)-http basic 인증
- java web-mvc
- system.io
- In App Purchase
- java-개발 환경 설정하기
- 스프링 프레임워크(spring framewordk)
- java.sql
- 제품 등록
- await
- .submit()
- 스프링 프레임워크(spring framework)
- 람다식(lambda expression)
- 특정 문자를 기준으로 자르기
- React
- jstl(java standard tag library)-core
- java 키워드 정리
- 메이븐(maven)
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함