Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

LINQ query to join 2 datasets and return matched field

Hi Guys, this will take some explaining, but hopefully the solution wont be so complicated.

I'm receiving a message (Via an event) the message has a Dictionary property called fields.

The fields can be as:

Key                        Value
UpdatedValue      "Email Address"

Key                     Value
FistName            "Persons First Name"
Surname            "Persons Surname Name"
Title                     "Persons Title"

Key               Value
Address1         "64 The Road"
Address2         "Westminster"
Town                  "London"
Postcode.         "W145QW"

At the time the message is received I wont know what is in the message.fields.

The message also includes a separate key to match up with database fields in the Key Column above. I'm using a DAO query to pull back a recorset  that looks something like this respectivly.

(DAO recordset Object)
QuestionKey      Key                     ID      LastUpdated      
String               UpdatedValue   200      2021-12-01

QuestionKey      Key                  ID      LastUpdated      
Name                  FistName      167      2021-12-01
Name                  Surname      168      2021-12-01
Name                  Title               169      2021-12-01

QuestionKey      Key               ID            LastUpdated  
Address            Address1      167         2021-12-01
Address            Address2      168         2021-12-01
Address            Town               169      2021-12-01
Address            Postcode         115      2021-12-01

So I have 2 sets of data, a dictionary of keys and values, and a DAO with keys and Id's.

I'm looking to LINQ to iterate over the Dictionary and for each item get me the id and LastUpdated date based on matching Keys. (I pass these values into a method to do stuff with.)


Avatar of louisfr

It's not clear what is contained in that message.fields Dictionary. Are "String", "Name", "Address" keys in that dictionary ? What is the exact type of that Dictionary ?
Avatar of Andy Green


The message.fields contains a key to the DAORecorset and a value. the key is commin and is used to join the 2 tables. Its a Dictionary<string,string>

This is what I have so far:
   var query = from m in message.Key
                  join fmd in DAORecordset
                  on m.Key equals fmd.Key
                  select new
And I'm able to iterate over

foreach (var item in query)
Avatar of Andy Green
Andy Green
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial