vb.net - best way to compare differences between lists -
i have 2 sets of lists below:
list 1 info
id = 1
personfirstname = sarah
personlastname = smith
personfavoritefood = pizza
personfavoritecolor = purple personfavoriteflower = lily
list 2 info
id = 1
personfirstname = sarah
personlastname = smith
personfavoritefood = hamburger
personfavoritecolor = yellow
personfavoriteflower = rose
as can see - sarah smith came system , changed favorite food, favorite color , favorite flower. if manager come app , open see 3 rows in history of sarah smith's record:
date changed = 2/16
field changed = personfavoritefood
original value = pizza
changed value = hamburger
changed = sarah smith
date changed = 2/16
field changed = personfavoritecolor
original value = purple
changed value = yellow
changed = sarah smith
date changed = 2/16
field changed = personfavoriteflower
original value = lily
changed value = rose
changed = sarah smith
the threee rows sees need saved in database in way. thats 1 table 2 rows (original row , changed row) , table many rows there changes , changes (food, color, flower). can first table original , changed row. suck in vb.net code going through linq on these 2 lists (the original , changed). thought select value each column in each list, determine if different, if save other table, if isn't next column each list , compare. there easier way?
my link code is:
dim columnvalue1 = in originallist select a.column1 dim columnvalue2 = b in changedlist select a.column1 if columnvalue1 = columnvalue2 savedifferencestotable(colomnvalue1, columnvalue2) end if
if there better way if outside of linq please let me know. can way worry wrong way it. using entity framework well.
you can use enumerable.except method create set of differences. can implement own comparer if have to. in anyway, sure have write code.
here more details on method:
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.except.aspx
Comments
Post a Comment