I need to push changes from a SQL server database to CRM. There are two tables on the SQL side:
Transfer
- TransferID (sequential)
- Entity (string, the SQL table name)
- PKOfEntity (int, also from the table)
- Action (create, update, destroy)
TransferField
- FieldID (sequential)
- TransferID (foreign key)
- FieldName (string)
- FieldValue (string)
Now, I need to get these changes into the CRM. I have a mapping of SQL tables to CRM entities, and one of SQL columns to CRM attributes. I do not, however, have a mapping of CRM attributes to CRM types on hand.
I'm using the Microsoft.Xrm.Sdk.Client.OrganizationServiceContext
object. Its SetAttributeValue
method takes an object, but it doesn't do any conversions; an int field requires passing in an int, and so on. Now, I would really, really, really like to just be able to pass in the field names and values dynamically as strings in one simple foreach, rather than manually checking for and setting dozens of attributes for dozens of models. Is there a reasonable way of doing this?