在我的控制器“语言”中,我有以下创建操作方法
<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
在创建之前如何检查数据库中是否存在具有相同值的重复项?