仅更新一行中的字段子集

时间:2012-05-14 09:37:23

标签: asp.net asp.net-mvc asp.net-mvc-3

我正在学习asp.net MVC。使用Code First模型,在其中创建类,然后使用EF管理所有数据库交互。

是否只使用此方法请求给定表中的某些字段,并且仅更新这些字段?

我全班同学:

Public Class Employee
  Public Property ID() As Integer
  <DisplayName("Staff Name")>
  <Required()>
  Public Property StaffName() As String
  <DisplayName("Location")>
  <Required()>
  Public Property Location() As String
  <Required()>
  <DisplayName("Team Leader")>
  Public Property teamleader() As String

  Public Property ScoreCardM1() As Integer
  Public Property ScoreCardM1Notes() As String
  Public Property ScoreCardM2() As Integer
  Public Property ScoreCardM2Notes() As String
  Public Property ScoreCardM3() As Integer
  Public Property ScoreCardM3Notes() As String
  Public Property ScoreCardM4() As Integer
  Public Property ScoreCardM4Notes() As String
  Public Property ScoreCardM5() As Integer
  Public Property ScoreCardM5Notes() As String
  Public Property ScoreCardM6() As Integer
  Public Property ScoreCardM6Notes() As String
  Public Property ScoreCardTotal() As Integer
  Public Property ScoreCardTotalNotes() As String
  Public Property ScoreCardM7() As Integer
  Public Property ScoreCardM7Notes() As String
  Public Property ScoreCardM8() As Integer
  Public Property ScoreCardM8Notes() As String
  Public Property ScoreCardM9() As Integer
  Public Property ScoreCardM9Notes() As String
  Public Property ScoreCardQ3Total() As Integer
  Public Property ScoreCardQ3TotalNotes() As String
  Public Property ScoreCardM10() As Integer
  Public Property ScoreCardM10Notes() As String
  Public Property ScoreCardM11() As Integer
  Public Property ScoreCardM11Notes() As String
  Public Property ScoreCardM12() As Integer
  Public Property ScoreCardM12Notes() As String
  Public Property ScoreCardQ4Total() As Integer
  Public Property ScoreCardQ4TotalNotes() As String
  Public Property GeneralNotes() As String
End Class

但是,我只想一次显示和编辑一个月:

Public Class Employee
  Public Property ID() As Integer
  <DisplayName("Staff Name")>
  <Required()>
  Public Property StaffName() As String

  Public Property ScoreCardM1() As Integer
  Public Property ScoreCardM1Notes() As String
End Class

我如何才能最好地实现这一目标?我是否设置了另外12个类,每个类只包含一个月,或者是否有更新数据库行中字段子集的最佳实践方法,而不会影响其他类?

感谢您的帮助,

标记

1 个答案:

答案 0 :(得分:0)

继上面我的评论....你可以设置你的课程如下:

员工类:

Public Class Employee
  Public Property EmployeeID() As Integer
  <DisplayName("Staff Name")>
  <Required()>
  Public Property StaffName() As String
  <DisplayName("Location")>
  <Required()>
  Public Property Location() As String
  <Required()>
  <DisplayName("Team Leader")>
  Public Property teamleader() As String
  Public virtual Property reports() As ICollection<Of MonthlyRports> // not sure if the syntax is right (haven't worked in VB)
End Class

MonthlyReport Class

Public Class Employee
  Public Property MonthlyReportID() As Integer // primary key
  Public Property EmployeeID() As Integer // foreign key. who this report belongs to
  Public Property Month As String // report for month ...
  Public Property ScoreCard() As Integer
  Public Property ScoreCardNotes() As String
End Class