DB : MySQL
๐ฅ ๋ฌธ์ ๋ฐ์
- ์ฌ๋ฌ ์ธ์ ๊ฒฐ๊ณผ๊ฐ์ DB์ Insert ํ๋ ๊ณผ์ ์์ ์ค๋ฅ ๋ฐ์
- for๋ฌธ์ ํตํด ํ๋์ฉ DB Insert ํ์์ง๋ง ์ค๋ฅ ๋ฐ์ or ๋ง์ง๋ง ํ๋์ ๊ฐ๋ง Insert ๋๋ ํ์ ๋ฐ์
- ๊ธฐ์กด์๋ ์ ์ญ๋ณ์๋ก entity๋ฅผ ์ ์ธํ์ฌ ์ฌ๋ฌ ์ธ์ ๊ฐ์ for์ ํตํด DB์ Insertํ๋ ค ํ๋ค.
public class Process()
{
public Process(DBContext context)
{
_context = context;
}
var entity = new ResultModel();
...
// process result type is List<string>
// process result name is rstList
for (int i = 0; i < rstList.Count; i++)
{
....
entity.resultCode = 0;
entity.resultMsg = "์ ์";
_context.DbinsOcrResult.Add(entity);
_context.SaveChanges();
}
}
โญ ํด๊ฒฐ๋ฐฉ๋ฒ
- entity ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌ์คํธ์ ๋ด์์ ๋ณด๊ดํ์ฌ ํ๋ฒ์ DB์ Insert ํ๋ค.
- ⇒ entity ์์ฒด์ ๊ฐ์ด ๋ณํ๊ธฐ ๋๋ฌธ์ ๋ฆฌ์คํธ์๋ ๋์ผํ ๊ฐ์ด ์ฌ๋ฌ๊ฐ ๋ค์ด๊ฐ๊ฒ ๋๋ค.
public class Process()
{
public Process(DBContext context)
{
_context = context;
}
var entity = new ResultModel();
List<ResultModel> resultList = new List<ResultModel>();
...
// process result type is List<string>
// process result name is rstList
for (int i = 0; i < rstList.Count; i++)
{
....
entity.resultCode = 0;
entity.resultMsg = "์ ์";
resultList.add(entity);
}
_context.DbinsOcrResult.AddRange(resultList);
_context.SaveChanges();
}
2. for๋ฌธ ์์ entity ๋ฅผ ์ง์ญ๋ณ์๋ก ์ ์ธํ์ฌ ํ๋์ฉ ๋๋น์ Insert ํด์ฃผ๋ ์์ ์ ํ์๋ค.
public class Process()
{
public Process(DBContext context)
{
_context = context;
}
...
// process result type is List<string>
// process result name is rstList
for (int i = 0; i < rstList.Count; i++)
{
....
var entity = new ResultModel();
entity.resultCode = 0;
entity.resultMsg = "์ ์";
_context.DbinsOcrResult.Add(entity);
_context.SaveChanges();
}
}728x90
๋ฐ์ํ
'TroubleShooting' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ์๋ณตํธํ (0) | 2025.11.25 |
|---|---|
| DB ๊ฐ SetValue๋ฅผ ์ด์ฉํด ๊ฐ Insert (0) | 2025.11.25 |