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)

Empty fields in LINQ query

(0) ShareShare
ReportReport
Posted on by 300

This is the query I'm currently using. 

Dim account_lookup = From a In srvContext.CreateQuery("account")

Order By a("name")

Where (CStr(a("statecode")).Equals("Active"))

 Select a.Attributes("name")

 

But I'd like to eliminate from the result list all records with xrx_site is NULL.  I've been unable to identify empty or null fields.

Where (CStr(a("xrx_site")).ISNULL) ???

*This post is locked for comments

I have the same question (0)
  • Aileen Gusni Profile Picture
    44,524 on at

    Hi mnicks,

    But I'd like to eliminate from the result list all records with xrx_site is NULL.  I've been unable to identify empty or null fields.

    --> You want to exclude the data with xrx_site is null or you want to show if it is null.

    And what is the xrx_site data type

     

    If using C# you can refer to this article:

    msdn.microsoft.com/.../gg509028.aspx

    And from here :

    int accountsWithCounty = (from a in svcContext.AccountSet

                                  where (a.Address1_County != null)

                                  select new Account

                                  {

                                   Name = a.Name,

                                   Address1_City = a.Address1_City

                                  }).ToArray().Count();

    You can get :

    where (a.Address1_County != null)

    If this is in VB I think you can use this:

    Where (a.Address1_County IsNot Nothing) _ // or Is Nothing  if you want to show the data if no value.

    where this field is a string (text)

    Or you can try this:

    stackoverflow.com/.../vb-net-linq-to-entities-null-comparison-is-nothing-or-nothing

    http://stackoverflow.com/questions/2319860/linq-query-where-column-contains-null-values

    Or you can also see this article:

    https://social.microsoft.com/Forums/en-US/ae85b054-d0bb-4101-a685-f1b4028ca6fe/crm-2011-query-with-linq-null-values?forum=crmdevelopment

    Or you can use Query Expression, instead:

    https://crmbusiness.wordpress.com/2012/03/22/crm-2011-queryexpressions-where-a-field-is-null/

    Hope this helps!

    Thanks.

  • mnicks Profile Picture
    300 on at

    Thanks for your reply.  It is vb.net and it is a string.

    However, with this code:

                       Dim account_lookup = From a In srvContext.CreateQuery("account")

                           Order By a("name")

                           Where (CStr(a("statecode")).Equals("Active"))

                           Where a.Attributes("xrx_site") IsNot Nothing

                               Select a.Attributes("name")

    I get this error:

    Invalid 'where' condition. An entity member is invoking an invalid property or method.

  • Royal King Profile Picture
    27,686 on at

    Try with below syntax to remove all null value data in vb.

    Where a.Attributes("xrx_site")  <> Nothing

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