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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX2012 LINQ - Using "Contains" with List

(0) ShareShare
ReportReport
Posted on by 11,279

Hi all,

I tried the C# code below and it throws an NotSupportedException when the code hit the foreach loop.

Error message:
The type 'System.Collections.Generic.List`1[[System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' for the query operator is not Queryable!

// Code sample
var recIdList = new List<long> { 5637144585, 5637144599, 5637144600 };

QueryProvider provider = new AXQueryProvider(null);
var CustInvoiceJour = new QueryCollection<CustInvoiceJour>(provider);
var invoiceJours = from ij in CustInvoiceJour                               
                   where recIdList.Contains(ij.RecId)
                   select ij;            

foreach (var invoiceJour in invoiceJours)
{
  // Do something
}

Anyone knows a way to get the above to work? Or another way to implement the above?

Thanks.

*This post is locked for comments

  • Community Member Profile Picture
    on at

    var invoiceJours = from ij in CustInvoiceJour                              

                      where recIdList.AsQueryable().All(Ids => Ids > 0)

                      select ij;

    OR

    var invoiceJours = from ij in CustInvoiceJour                              

                      where recIdList.All(Ids => Ids > 0)

                      select ij;

  • dolee Profile Picture
    11,279 on at

    Hi VDY,

    The first option produce: The expression of type 'System.Linq.IQueryable`1[System.Int64]' is not a sequence

    The second option produce: The expression of type 'System.Collections.Generic.List`1[System.Int64]' is not a sequence

    No luck so far, but thanks anyway. =]

  • Verified answer
    Martin Dráb Profile Picture
    240,854 Most Valuable Professional on at

    If you wrote the query directly in AX, how would it look like? AX obviously don't have any notion of Contains operator, so it's not clear how you want the LINQ provider to translate it into AX. Think about how would you do it in AX and then use the same approach in LINQ to AX.

  • dolee Profile Picture
    11,279 on at

    I have moved on and use another approach for the implementation.

    Thanks for the answers Martin and VDY.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans