1
我試圖在組織文檔中插入「視頻」的子類(文檔)。將子陣列插入到Azure的文檔數據庫中
但是,當我嘗試添加記錄時,我得到「對象引用未設置爲對象的實例」。
我試圖使用添加和插入,但都沒有工作。我看着Dcoument資源管理器,我可以看到視頻返回「null」。
我假設我的問題是文檔數據庫不知道視頻是一個列表。 (在我的模型中,我已將其定義爲列表)
此外,我嘗試爲組織和視頻創建新對象。另外,我有一個名爲Category的類,它具有完全相同的代碼(除了對象是Category)並且它插入正確。
下面是我正在使用的操作。
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "name,description,link")] Video video)
{
if (ModelState.IsValid)
{
UserSession usersession = new UserSession();
usersession = (UserSession)Session["user"];
Organization organization = (Organization)DocumentDBRepository<Organization>.GetItem(d => d.Id == usersession.organizationId);
video.DateAdded = DateTime.Now;
organization.Videos.Add(video);
await DocumentDBRepository<Organization>.UpdateItemAsync(organization.Id, organization);
return RedirectToAction("Index");
}
return View(video);
}
備註 - 我也嘗試過ReplaceDocumentAsync(這是UpdateItemAsync調用的內容 –