When working on a code upgrade I'm having troube comparing a optionsetvalue to an int.
The fix I put in (via a visual studio suggestion) doesn't work.
Can anyone point me in the right direction?
Thanks
my code is
IEnumerable<int?> myVariable = from entity in serviceContext.crm_entitySet
where entity.statuscode == 1
&& entity.crm_enityItemId.Id == _entityItemId
select entity.statuscode;
the error is on there "where entity.statuscode == 1" line
Converting the linq statement to OptionSetValue, then adding a ToList() to the result before the Count() was the solution to this.
I've tried casting the result into what I need, but I'm now getting this error
Unable to cast object of type 'Microsoft.Xrm.Sdk.Linq.Query`1[Microsoft.Xrm.Sdk.OptionSetValue]' to type 'System.Collections.Generic.IEnumerable`1[System.Nullable`1[System.Int32]]'
Thanks, that's broadly solved the first problem.
However I now need to convert that to an int. Using a new line of code.
Everything I'm trying to convert that is failing, do you have any ideas?
Thanks
Lee
Sorry for my partial answer.
If you want to select the option set value only:
IEnumerable<int?> myVariable = from entity in serviceContext.crm_entitySet
where entity.statuscode.Value == 1
&& entity.crm_enityItemId.Id == _entityItemId
select entity.statuscode.Value;
If you want to select the OptionSetValue:
IEnumerable<OptionSetValue?> myVariable = from entity in serviceContext.crm_entitySet
where entity.statuscode.Value == 1
&& entity.crm_enityItemId.Id == _entityItemId
select entity.statuscode;
Good luck !
Thanks for replying, however it was the first thing I try and brings up the new error
Cannot implicidly convert type 'System.Linq.IQueryable<Microsoft.Crm.Sdk.OptionSetValue>' to 'System.Collections.Generic.IEnumberable<int?>'
and then suggests an explict cast for the whole piece of code not just that line
However that cast was the fix I put in which has failed.
Thanks
Lee
Hi,
try this: "where entity.statuscode.Value == 1"
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156