我需要將來自DB的對象的當前列表與新對象列表進行比較。我想比較它們並突出顯示已更改的用戶(在這種情況下,返回TRUE表示它們不同)。如何比較可空對象
由於一些我的對象是空的,這涉及到很多IF NOT的是關於NewObj和CurrentObj側面沒什麼......我一直試圖找到寫下面的,因爲我有一個更有效的方法用它來比較約30個不同類型,即日期,小數,INT,等一個對象..
下面的作品,直到說無論是obj的無等級,因此沒有
建議?
Dim Rank As Boolean = CompareData(NewObj, CurrentObj, "Rank")
Dim Regiment As Boolean = CompareData(NewObj, CurrentObj, "Rank")
Dim DateofBirth As Boolean = CompareData(NewObj, CurrentObj, "DoB")
Private Function CompareData(NewObj As Business.Casualty, CurrentObj As Business.Casualty, FieldToComapre As String) As Boolean
Select Case FieldToComapre
Case "DateOfBirth"
Return (Nullable.Equals(NewCasualty.DateOfBirth, CurrentCasualty.DateOfBirth))
Case "Age"
Return (Nullable.Equals(NewCasualty.Age, CurrentCasualty.Age))
Case "Rank"
Return (Nullable.Equals(NewCasualty.Rank.ID, CurrentCasualty.Rank.ID))
Case "Regiment"
Return (Nullable.Equals(NewCasualty.Regiment.ID, CurrentCasualty.Regiment.ID))
Case Else
Return True
End Select
End Function