Avatar of Andy Green
Andy Green
Flag 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:

(Dictionary)
String
Key                        Value
UpdatedValue      "Email Address"

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

Address
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)
String
QuestionKey      Key                     ID      LastUpdated      
String               UpdatedValue   200      2021-12-01

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

Address
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.)


Andy

LINQ Query* ASP.NET CoreASP.NET

Avatar of undefined
Last Comment
Andy Green

8/22/2022 - Mon
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 ?
Andy Green

ASKER
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
                  {
                     m.Value,
                     fmd.QuestionId,
                     fmd.LastUpdated
                  };
And I'm able to iterate over

foreach (var item in query)
         {...}
ASKER CERTIFIED SOLUTION
Andy Green

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes