1

私はasp.netMVCを学んでいます。クラスを作成するCodeFirstモデルを使用してから、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

ただし、一度に表示および編集したいのは1か月だけです。

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

どうすればこれを最もよく達成できますか?それぞれに1か月だけ含まれる、別の12のクラスを設定しますか、それとも他のクラスに影響を与えずにデータベース行内のフィールドのサブセットを更新するベストプラクティスの方法がありますか?

助けてくれてありがとう、

マーク

4

1 に答える 1

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クラス

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
于 2012-05-14T14:04:54.090 に答える