Vb.net 使用EF模型数据库而不使用updateModel更新
MVC3,VB.NET,RAZOR应用程序,使用EF。我有一个问题,在我的职位功能与数据库没有更新在所有。。。在db.savechanges()处使用中断符查看变量,所有正确的信息都包含在UpdateModel()部分中。但是没有骰子代码执行并且没有返回错误,所以看起来一切正常,但是当我查看数据库表时,它根本没有被更改,所有的旧值仍然存在。。功能如下:Vb.net 使用EF模型数据库而不使用updateModel更新,vb.net,asp.net-mvc-3,entity-framework,Vb.net,Asp.net Mvc 3,Entity Framework,MVC3,VB.NET,RAZOR应用程序,使用EF。我有一个问题,在我的职位功能与数据库没有更新在所有。。。在db.savechanges()处使用中断符查看变量,所有正确的信息都包含在UpdateModel()部分中。但是没有骰子代码执行并且没有返回错误,所以看起来一切正常,但是当我查看数据库表时,它根本没有被更改,所有的旧值仍然存在。。功能如下: <AcceptVerbs(HttpVerbs.Post)> Function EditCourse(ByVal _eC
<AcceptVerbs(HttpVerbs.Post)>
Function EditCourse(ByVal _eCourse As cours) As ActionResult
Dim id As Integer = _eCourse.course_id
Dim _filename As String = String.Empty
Dim _guid As String = String.Empty
Dim _count As Integer = 0
Dim _courseFiles As cours = db.courses.Where(Function(f) f.course_ref = _eCourse.course_ref).First
Dim _file1 As String = _courseFiles.handoutFile1
Dim _file2 As String = _courseFiles.handoutFile2
Dim _file3 As String = _courseFiles.handoutFile3
Dim _file4 As String = _courseFiles.handoutFile4
Dim _file5 As String = _courseFiles.handoutFile5
Dim _file6 As String = _courseFiles.handoutFile6
Dim _file7 As String = _courseFiles.handoutFile7
Dim _file8 As String = _courseFiles.handoutFile8
For Each File As String In Request.Files
_count += 1
Dim hpf As HttpPostedFileBase = TryCast(Request.Files(File), HttpPostedFileBase)
If hpf.ContentLength = 0 Then
Continue For
End If
Dim savedfileName As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + hpf.FileName
hpf.SaveAs(savedfileName)
_filename = hpf.FileName
Select Case _count
Case Is = 1
If Not String.IsNullOrWhiteSpace(_file1) Then
If Not String.Compare(_eCourse.handoutFile1, _file1) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile1) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file1
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile1 = _filename
Case Is = 2
If Not String.IsNullOrWhiteSpace(_file2) Then
If Not String.Compare(_eCourse.handoutFile2, _file2) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile2) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file2
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile2 = _filename
Case Is = 3
If Not String.IsNullOrWhiteSpace(_file3) Then
If Not String.Compare(_eCourse.handoutFile3, _file3) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile3) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file3
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile3 = _filename
Case Is = 4
If Not String.IsNullOrWhiteSpace(_file4) Then
If Not String.Compare(_eCourse.handoutFile4, _file4) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile4) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file4
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile4 = _filename
Case Is = 5
If Not String.IsNullOrWhiteSpace(_file5) Then
If Not String.Compare(_eCourse.handoutFile5, _file5) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile5) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file5
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile5 = _filename
Case Is = 6
If Not String.IsNullOrWhiteSpace(_file6) Then
If Not String.Compare(_eCourse.handoutFile6, _file6) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile6) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file6
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile6 = _filename
Case Is = 7
If Not String.IsNullOrWhiteSpace(_file7) Then
If Not String.Compare(_eCourse.handoutFile7, _file7) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile7) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file7
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile7 = _filename
Case Is = 8
If Not String.IsNullOrWhiteSpace(_file8) Then
If Not String.Compare(_eCourse.handoutFile8, _file8) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile8) Then
Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file8
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
End If
_eCourse.handoutFile8 = _filename
End Select
Next
UpdateModel(_eCourse)
db.SaveChanges()
Return RedirectToAction("CourseIndex")
End Function
函数EditCourse(ByVal _eCourseas cours)作为ActionResult
Dim id为整数=\u eCourse.course\u id
Dim\u文件名为String=String.Empty
Dim\u guid为String=String.Empty
Dim _计数为整数=0
Dim\u coursefile作为cours=db.cours.Where(函数(f)f.course\u ref=\u eCourse.course\u ref)。首先
Dim _file1作为字符串=_courseFiles.handoutFile1
Dim\u file2作为字符串=\u courseFiles.handoutFile2
Dim\u file3作为字符串=\u courseFiles.handoutFile3
Dim\u file4作为字符串=\u courseFiles.handoutFile4
Dim\u file5作为字符串=\u courseFiles.handoutFile5
Dim\u file6作为字符串=\u courseFiles.handoutFile6
Dim\u file7作为字符串=\u courseFiles.handoutFile7
Dim\u file8作为字符串=\u courseFiles.handoutFile8
将每个文件作为Request.Files中的字符串
_计数+=1
Dim hpf As HttpPostedFileBase=TryCast(Request.Files(File),HttpPostedFileBase)
如果hpf.ContentLength=0,则
继续
如果结束
Dim savedfileName As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+hpf.FileName
hpf.SaveAs(savedfileName)
_filename=hpf.filename
选择Case\u count
情况是=1
如果不是String.IsNullOrWhiteSpace(_file1),则
如果不是String.Compare(_eCourse.handoutFile1,_file1)=0,也不是String.IsNullOrWhiteSpace(_eCourse.handoutFile1),则
Dim FileToDelete As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+\u文件1
如果System.IO.File.Exists(FileToDelete)=True,则
System.IO.File.Delete(FileToDelete)
如果结束
如果结束
如果结束
_eCourse.handoutFile1=\u文件名
情况是=2
如果不是String.IsNullOrWhiteSpace(_file2),则
如果不是String.Compare(_eCourse.handoutFile2,_file2)=0,也不是String.IsNullOrWhiteSpace(_eCourse.handoutFile2),则
Dim FileToDelete As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+\u文件2
如果System.IO.File.Exists(FileToDelete)=True,则
System.IO.File.Delete(FileToDelete)
如果结束
如果结束
如果结束
_eCourse.handoutFile2=\u文件名
情况是=3
如果不是String.IsNullOrWhiteSpace(_file3),则
如果不是String.Compare(_eCourse.handoutFile3,_file3)=0,也不是String.IsNullOrWhiteSpace(_eCourse.handoutFile3),则
Dim FileToDelete As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+\u文件3
如果System.IO.File.Exists(FileToDelete)=True,则
System.IO.File.Delete(FileToDelete)
如果结束
如果结束
如果结束
_eCourse.handoutFile3=\u文件名
情况是=4
如果不是String.IsNullOrWhiteSpace(_file4),则
如果不是String.Compare(_eCourse.handoutFile4,_file4)=0,也不是String.IsNullOrWhiteSpace(_eCourse.handoutFile4),则
Dim FileToDelete As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+\u file4
如果System.IO.File.Exists(FileToDelete)=True,则
System.IO.File.Delete(FileToDelete)
如果结束
如果结束
如果结束
_eCourse.handoutFile4=\u文件名
情况是=5
如果不是String.IsNullOrWhiteSpace(_file5),则
如果不是String.Compare(_eCourse.handoutFile5,_file5)=0,也不是String.IsNullOrWhiteSpace(_eCourse.handoutFile5),则
Dim FileToDelete As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+\u文件5
如果System.IO.File.Exists(FileToDelete)=True,则
System.IO.File.Delete(FileToDelete)
如果结束
如果结束
如果结束
_eCourse.handoutFile5=\u文件名
情况是=6
如果不是String.IsNullOrWhiteSpace(_file6),则
如果不是String.Compare(_eCourse.handoutFile6,_file6)=0,也不是String.IsNullOrWhiteSpace(_eCourse.handoutFile6),则
Dim FileToDelete As String=Path.Combine(AppDomain.CurrentDomain.BaseDirectory)+“\CourseHandouts\”+\u文件6
如果System.IO.File.Exists(FileToDelete)=True,则
系统