第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 RESTful Web 應(yīng)用程序中添加數(shù)據(jù)庫(kù)?

如何在 RESTful Web 應(yīng)用程序中添加數(shù)據(jù)庫(kù)?

C#
白板的微信 2022-07-23 17:03:21
我是新手,asp.net正在努力學(xué)習(xí)。因此,我使用在線教程( https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&tabs=visual-studio)中的代碼創(chuàng)建了一個(gè)項(xiàng)目以下課程??刂破鳎簄amespace WebApiSample.Controllers{    [Route("api/[controller]")]    [ApiController]    public class TodoController : ControllerBase    {        private readonly ToDoContext _context;        public TodoController(ToDoContext context)        {            _context = context;            if (_context.TodoItems.Count() == 0)            {                // Create a new TodoItem if collection is empty,                // which means you can't delete all TodoItems.                _context.TodoItems.Add(new ToDoItem { Name = "Item1" });                _context.SaveChanges();            }        }        // GET: api/Todo        [HttpGet]        public async Task<ActionResult<IEnumerable<ToDoItem>>> GetTodoItems()        {            return await _context.TodoItems.ToListAsync();        }        // GET: api/Todo/5        [HttpGet("{id}")]        public async Task<ActionResult<ToDoItem>> GetTodoItem(long id)        {            var todoItem = await _context.TodoItems.FindAsync(id);            if (todoItem == null)            {                return NotFound();            }            return todoItem;        }        // POST: api/Todo        [HttpPost]        public async Task<ActionResult<ToDoItem>> PostTodoItem(ToDoItem todoItem)        {            _context.TodoItems.Add(todoItem);            await _context.SaveChangesAsync();            return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);        }您可以看到它不使用任何數(shù)據(jù)庫(kù)。如何在這個(gè)項(xiàng)目中添加一個(gè)數(shù)據(jù)庫(kù),以便每當(dāng)我運(yùn)行它時(shí),我都可以獲得之前已經(jīng)添加的項(xiàng)目列表?有任何想法嗎?
查看完整描述

1 回答

?
精慕HU

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊

通常,實(shí)體框架將是最好的解決方案。下面是使用實(shí)體框架Entity Framework Databases Supported支持的數(shù)據(jù)庫(kù)的鏈接。但是,如果要連接到其他數(shù)據(jù)庫(kù),則需要進(jìn)行自己的CRUD 操作(創(chuàng)建、檢索、更新、刪除)。這是一個(gè)使用 MongoDB 的 CRUD示例



查看完整回答
反對(duì) 回復(fù) 2022-07-23
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)