Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to check Entity Value null and count in single condition

(0) ShareShare
ReportReport
Posted on by 475

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

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 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.

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 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

  • Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 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 ...

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans