D365: Value cannot be null. Parameter name: attributeName
Views (3403)
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 !!
This was originally posted here.

Like
Report
*This post is locked for comments