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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

NotSupportedException when trying to do a Linq query

(0) ShareShare
ReportReport
Posted on by 70

Hello ax Newbie here.

An unhandled exception of type 'System.NotSupportedException' occurred in Microsoft.Dynamics.AX.Framework.Linq.Data.dll

I'm trying this simple Linq query, but im getting the above exception. Operands work just fine (like == or !=), but cant get this to work.

I assume the backend provider don't have Idea of how to translate the .Contains method, so if so, do you guys have an idea of how can I workaround this?

pastedimage1625318836379v1.png

pastedimage1625318880655v2.png

My piece of code in case the images won't load

static void Main(string[] args)
{

Session axSession = new Session();
axSession.Logon(null, null, null, null);

QueryProvider provider = new AXQueryProvider(null);
var purchases = new QueryCollection<PurchTable>(provider);
var purchasesQuery = from p in purchases
where p.PurchId.Contains("P453321")
select new { p.PurchId };
foreach (var purchase in purchasesQuery)
{
Console.WriteLine(purchase);

}
Console.Read();
axSession.Logoff();

}

I have the same question (0)
  • Suggested answer
    greengrimms Profile Picture
    1,400 on at

    Hi Jairo,

    So what you're trying to achieve can easily be done through an x++ query. i suggest you take a look at this MS docs first for more insight:

    docs.microsoft.com/.../how-to-create-queries-by-using-x

    docs.microsoft.com/.../xpp-data-home-page

    docs.microsoft.com/.../select-statement-examples

    Hope it helps.

  • JairoJs Profile Picture
    70 on at

    Hello Danilo Bambi Thanks for your reply. your answer is a way to go. But what if im trying to build some sort of API for an MVC design and I'm trying to write all my controllers in managed code. How can I access the query made in X++ from my C#. what I'm saying makes sense, Is it an efficient approach?

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at

    Hi Jairo,

    I see you're working on AX 2012. I suggest taking a look at the capabilities of AIF and Business connector for exposing the application:

    docs.microsoft.com/.../integration-with-microsoft-dynamics-ax

    Also a document on how to use LINQ with AX:

    docs.microsoft.com/.../code-example-linq-to-ax-from-csharp

    And in the remote case that you're working with Finance & Operations, the right way to expose data and communicate with the application would be through OData: docs.microsoft.com/.../build-consuming-data-entities

    Let me know if this helps.

  • JairoJs Profile Picture
    70 on at

    I see. Yes I am on Ax2012. but am I not using bussines connector already? by using axSession, QueryProvider and QueryCollection.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 659 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 533 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 289 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans