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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to check Entity Value null and count in single condition

(0) ShareShare
ReportReport
Posted on by 483

How to check Entity Value null and count in single condition instead to add one more if condition to check if ecAccount ?

with the following code it will get error if ecAccount is Null is there any other to avoid error with single line condition in c# ?

if (ecAccount == null && ecAccount.Entities.Count <= 0)
return null;

*This post is locked for comments

I have the same question (0)
  • Temmy Wahyu Raharjo Profile Picture
    2,916 on at
    RE: How to check Entity Value null and count in single condition

    if you get result from Service.RetrieveMultiple. The result will never send you null object. So you can used if(!ecAccount.Entities.Any()) return ...

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at
    RE: How to check Entity Value null and count in single condition

    Hi Kirshna,

    If you are using the retrievemultiple then  

    use

    if(ecAccount.Entities.Count == 0)

    if you are using retrieve then

    use

    if (ecAccount == null )

    Thanks

    Hemant

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: How to check Entity Value null and count in single condition

    Hi Krishna,

    Usually you use it other way around and then put your logicin else reason i.e.

    If(ecAccount != null && ecAccount.Entities.Count > 0)

    {

       /// Logic on the returned records

    }

    else

    {

    // Display error message or return null error

    return null;

    }

    Hope this helps.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans