I'm building a .net console application to query certain crm records (8.2 on-prem) and save the field values to an xml file. For example I want to query a contact and get values from 20 fields. I'm using entity framework 6 and I created a db and table where one of the columns has the 20 fields names that I want to use in my query e.g. firstname, lastname, email, etc.. How can I use the list of fields that I get from my ef context/dbset in a linq query?
var context = new DBContext();
foreach (var field in context.DBSet)
{
Console.WriteLine(field.CrmField);
}
In code above, field.CrmField are all the field names that I'm trying to use in my linq query below:
var linq_query = from c in orgSvcContext.CreateQuery("contact")
where (String)c["trigger_field"] == "100000001"
select new
{
//Instead of hardcoding these values, I'd like to use the list from ef above
contact_id = c["contactid"],
first_name = c["firstname"],
last_name = c["lastname"]
};
foreach (var record in linq_query)
{
Console.WriteLine($"Linq: {record.first_name} {record.last_name} - contactid:{record.contact_id}");
}
*This post is locked for comments
I have the same question (0)