c# - Entity Framework compare two data sets -


i have situation need compare 2 sets of data sql server. 1 set of data held in table (which modelled in entity framework model), other result set of stored procedure. fields returned stored procedure identical fields in table.

i had thought following work:

using (var db = new mydatabasecontext()) {     dbset<mytable> tabledata = db.mytables;     dbset<mytable> procdata = db.set<mytable>();     procdata.addrange(db.mytables.sqlquery("exec dbo.myproc").tolist();      if (tabledata.count != procdata.count) return false;      foreach (var data in tabledata) {         if (!data.equals(procdata.find(data.id))) return false;     } } 

(side note: mytable class has been edited implement iequatable , override equals it's suitable comparing @ field level)

the logic being believed db.set<mytable> create arbitrary empty set of mytables populate result of stored procedure, , compare data in table.

it appears i've misunderstood this, however, checking contents of tabledata , procdata @ first if line shows both contain same data (i've purposefully editted stored procedure not return same data in table), leading me believe db.set<table> , db.mytables both reference same thing.

how can achieve this?

db.mytables has same definition returned in line defining procdata , contains same objects.

(i assume dbcontext has following, or equivalent):

public dbset<mytable> mytables { get; set; }

calling db.set<mytable>() give set equivalent property defined on context.

if filtering in stored procedure tabledata contains records (so procdata). when attempt add more records (which ostensibly same records contained in set), ef try , add records state of "added". thing is, comparison isn't testing difference in state, , ef might not consider them added (if configured primary keys so, ef might determine records exist , state changes unnecessary).


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -