D365: Value cannot be null. Parameter name: attributeName

Recently, while trying to retrieve records in D365 CE using LINQ, we got the following error message “Value cannot be null. Parameter name: attributeName”. There was not much information in the stack trace as well.

We were using below code to get records based on certain condition from 2 entities putting join as shown below:

var serviceEntries = (from s in ctx.dxc_serviceentrySet
                                      join sd in ctx.dxc_servicedetailsSet
                                      on s.dxc_servicedetailsid.Id equals sd.Id
                                      where s.StateCode == dxc_serviceentryState.Active
                                      && sd.Id == new Guid("D3DB63F4-3C14-4B20-AE96-FA8D6E77BED0")
                                      select s).ToList();

To resolve this issue, we changed Id attribute to the schema name of the primary key field of the entity as shown below and it started working.

 var serviceEntries = (from s in ctx.dxc_serviceentrySet
                                      join sd in ctx.dxc_servicedetailsSet
                                      on s.dxc_servicedetailsid.Id equals sd.dxc_servicedetailsId
                                      where s.StateCode == dxc_serviceentryState.Active
                                      && sd.dxc_servicedetailsId == new Guid("D3DB63F4-3C14-4B20-AE96-FA8D6E77BED0")
                                      select s).ToList();

Using Id instead of primary key schema name in join or any condition while retrieving records does not work with LINQ. Hope it helps !!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.