Tuesday, September 20, 2011

CRM 2011 - Moniker

To Map Many To Many Relation Ship Use Moniker Like This in Crm 2011
User EntityReference instead of Moniker
-------------------------------------------------------------------

Microsoft.Xrm.Sdk.EntityReference Moniker1 = new Microsoft.Xrm.Sdk.EntityReference { Id = new Guid ( contactID ), Name = "contact" };
Microsoft.Xrm.Sdk.EntityReference Moniker2 = new Microsoft.Xrm.Sdk.EntityReference { Id = new Guid ( id ), Name = "fia_newsletter" };


string strManyToManyRelationshipName = "fia_contact_fia_newsletter";


isSuccess = newsLetterBO.AssociateManyToManyEntityRecords ( Moniker1, Moniker2, strManyToManyRelationshipName );


--------------------------------------------------------------------------------

public bool AssociateManyToManyEntityRecords ( EntityReference moniker1, EntityReference moniker2, string strEntityRelationshipName )
{
try
{
// Create an AssociateEntities request.
AssociateEntitiesRequest request = new AssociateEntitiesRequest ( );


// Set the ID of Moniker1 to the ID of the lead.
request.Moniker1 = new EntityReference { Id = moniker1.Id, LogicalName = moniker1.Name };


// Set the ID of Moniker2 to the ID of the contact.
request.Moniker2 = new EntityReference { Id = moniker2.Id, LogicalName = moniker2.Name };


// Set the relationship name to associate on.
request.RelationshipName = strEntityRelationshipName;


// Execute the request.
this.Service.Execute ( request );


return true;
}


catch ( SoapException ex )
{
return false;
}

}

-----------------------------------------------------------------
This is solution for the error
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

No comments:

Post a Comment

Post a Comment