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)

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

    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

    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

    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…

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