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();

}

  • JairoJs Profile Picture
    70 on at
    RE: NotSupportedException when trying to do a Linq query

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

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at
    RE: NotSupportedException when trying to do a Linq query

    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
    RE: NotSupportedException when trying to do a Linq query

    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
    RE: NotSupportedException when trying to do a Linq query

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans