web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

crmsvcutil.exe n:n properties not working?

(0) ShareShare
ReportReport
Posted on by

Hello - I used crmsvcutil to generate an object model. The generated object model looks the same as the previous generated object model, with the exception of 1 or 2 changes as expected. However, the N:N properties refs in the OM are no longer working. My plugin has existing code that uses dot notation to reference the N:N data. However, these references are now all null even when they should not be. I made a batch of a few different changes a few days ago so it's hard for me to know which change might have broken things. Here's an example of 1 of the N:N code properties created, that used to work but now doesn't:

/// <summary>
/// N:N new_CaseFinders
/// </summary>
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("new_CaseFinders")]
public System.Collections.Generic.IEnumerable<MyCo.Dashboard.CRM.Entities.Contact> new_CaseFinders
{
get
{
return this.GetRelatedEntities<MyCo.Dashboard.CRM.Entities.Contact>("new_CaseFinders", null);
}
set
{
this.OnPropertyChanging("new_CaseFinders");
this.SetRelatedEntities<MyCo.Dashboard.CRM.Entities.Contact>("new_CaseFinders", null, value);
this.OnPropertyChanged("new_CaseFinders");
}
}

Any idea what might have changed that could have broken this functionality? Any idea about what steps I can take to possibly restore this functionality? Thanks!

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    yes, the relationship still exists in CRM, and appears to get included in the object model, but all the plugin code references now return null data for those references.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    I suspect what has happened is that your Early bound types have been re-generated using CrmSvcUtil but not using the Microsoft.Xrm.Client extensions. The easiest way to check is look at one of your Early bound types and see what base class it is.

    If it inherts from 'Entity' that the relationships will not lazy load for you since you are not using the Client Extensions.

    The classes must inherit from 'Microsoft.Xrm.Client.CrmEntity' otherwise you'll need to manually call 'LoadProperty'

    Re-generate your types using the extensions - msdn.microsoft.com/.../gg695792.aspx

    hth

  • Community Member Profile Picture
    on at

    @Scott - In my first post, you can see the code snippet where it calls "LoadRelatedEntities."

    Is the "LoadProperty" method you're describing different than "LoadRelatedEntities"?

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Sorry, I've not seen your first post.

    The generated relationship collection accessors will make a call to 'GetEntiies', but this will return null unless you are using the CrmEntity base class or you have made a call 'LoadProperty':

    context.LoadProperty(theContact, "new_CaseFinders");

    hth

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    BTW - Do your early bound generated tasks inherit from CrmEntity or Entity?

  • Community Member Profile Picture
    on at

    Hi Scott - Thanks for your feedback.  I changed the base class to CrmEntity, however the N:N data still isn't getting populated.  Can you think of anything else that might be missing?

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    You shouldn't manually change the base class - you need to ensure that the CrmSvcUtil creates the entities with the CrmEntity as a base class - using the 'CodeGeneration' extensions with the syntax:

    CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization,Microsoft.Xrm.Client.CodeGeneration"  /url:http://server/org/XRMServices/2011/Organization.svc /out:"Xrm.cs" /namespace:Xrm

    You then need to make sure that you are using the CrmOrganizationServiceContext and not just the plain OrganizationServiceContext.

    If you do these things, your relationship attributes will lazy load automatically.

    hth

  • Community Member Profile Picture
    on at

    Hi Scott - We followed your advice in your last post:

    * All entities are now extending Microsoft.Xrm.Client.CrmEntity as expected.

    * XrmContext is now extending CrmOrganizationServiceContext instead of OrganizationServiceContext as expected.

    The N:N objects are being genned in the OM (like the old approach).  However, the OM is still not populating data into the N:N objects for access through dot notation (refs are null).

    Can you think of anything else that we might possibly be missing here?  If it seems that we've done everything we're supposed to do for the OM, then can you recommend an easy way for us to trigger the data load for the N:N objects programatically through our plugin code?  Right now we're having to resort to implementing fetchxml queries to get our N:N data in our plugins?

  • Verified answer
    ScottDurow Profile Picture
    21 on at

    That is odd - do all your other relationships lazy load correctly?

    You can manually load them using context.LoadProperty(theContact, "new_CaseFinders");

    hth

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans