1
在我的控制器「語言」我有以下的創建操作方法在MVC3中如何在數據庫中創建項目之前檢查重複項?
<HttpPost()>
Function Create(language As Language) As ActionResult
Try
If ModelState.IsValid Then
Dim name As String = language.Name
db.Languages.Add(language)
db.SaveChanges()
Return RedirectToAction("Index", New System.Web.Routing.RouteValueDictionary(New With {.languageName = name, .onSuccess = ActionType.CREATE}))
End If
Catch ex As DataException
ViewBag.ErrorTitle = Resources.Commands.UnableToCreate
ViewBag.ErrorMessage = Resources.Commands.TryAgainMessage
End Try
Return View(language)
End Function
我如何檢查是否產生之前就存在與數據庫中的值相同的重複?