We are facing the problem when we would like to develop a CRM library (manager) in C# which will support the communication with more than one CRM systems - i.e. the situation when you are running more than one CRM instances at once (e.g. two different organizations).
Requirements for the CRM library:
Use early-bound instead of late-bound (because of type safety)
Able to communicate with more CRM systems (organizations) through one manager
Only one method for one operation (avoid code duplication) used for all CRM systems (organizations) - it will be necessary to create an utility for parsing generated entity files (crmsvcutil tool) for each organization. The result of the parsing will be list of interfaces and partial classes for the entities defined in the entity files. The interfaces will be implemented in the partial classes according the attributes which they contain, like IAccountNumber etc. There will be two groups of interfaces - first one for the entity attributes common in both organization e.g. interface ICrmAccount will define AccountNumber, Name, Address1 attributes etc. The second group of interfaces will be for the attributes which are unique for entity and are not present in entity of ALL CRM systems (organizations). The general CRM manager will than offer all methods for the communication, like CreateAccount(), GetAccount() etc. which will then work with the specific CRM system due to implemented interfaces.
We have designed a solution which is now able to communicate with two different CRM systems but it is not able to use implemented interfaces for the specific account, see enclosed solution which contains comments of the code.
The solution can be found here:
Description of solution:
CRM_BusinessLogic - contains CRMManager which holds all methods for the communication and initialize correct data context in constructor
CRM_Interfaces - contains all generated interfaces which are result of entity files parsing (this will have to be done with separate parsing tool). Now contains only iCRMAccount holding only one attribute common for both organizations and iCRMContext which contains the entity which are implemented in both data contexts - now both contexts implementes same entity Account.
CRM_SCEurope - contains generated entity file for the first CRM organization SC Europe - SCEuropeEntities.cs, generated data context by the parsing tool (implements list of interface according which entities are present in the organization context) - SCEuropeContext_generated and SCEuropeContext.cs which returns the correct assembly
CRM_SoSW - the same content as CRM_SCEurope, contains the data related to the second CRM organization
CRM_Test - contains the test console app which will communicate with both organizations
Please note that enclosed solution only contains Account entity with only Name parameter which is enough for the basic testing of designed solution.
Important: Before run of the project you have to set credentials for the manager in the Program.cs file (CRM_Test project).
As you can see if the Account data are loaded from the CRM using the generated partial classes (SoSwContext,SCEuropeContext) with implemented interface iCRMContext, the application throws an exception "Invalid 'where' condition. An entity member is invoking an invalid property or method - see the method implementation.".
We will appreciate if anybody will find a solution how to solve the exception.
Thanks
Pavel