LINQ to dataset

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
philip.joebstl
Posts: 26
Joined: Tue Oct 09, 2012 12:56 am

LINQ to dataset

Post by philip.joebstl »

Hi there,

I am working on a TxA- and -B- Series Target programming an application with database connection. So i thought about using a dataset and the "LINQ to Dataset" functionality. So I wrote the following code:

DataSet ds;
...
var result = ds.Tables["tabRecipe"].AsEnumerable()
.Where(row => row.IDRecipe == iIDRecipe && row.Priority >= iStepPriority)
.OrderBy(row => row.Priority)
.FirstOrDefault();
...

But when I'm trying to compile, the following error comes on:
"System.Data.DataTable" has no definition for "AsEnumerable", and there was no extension method "AsEnumerable...

The Microsoft .net documentation about LINQ in the .net cf says that LINQ to Dataset is also working on cf, and also the "AsEnumerable"-Method should be (like you can see here: http://msdn.microsoft.com/de-de/library ... 90%29.aspx)

So why does this piece of code not compile?

Thanks for the help!
Best regards,
Philip Joebstl

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: LINQ to dataset

Post by mark.monroe »

Only some of the methods are supported in CF and the AsEnumerable is not supported.

http://msdn.microsoft.com/en-us/library ... s.90).aspx
Snap 2013-09-06 at 11.04.00.jpg
Snap 2013-09-06 at 11.04.00.jpg (46.4 KiB) Viewed 14192 times
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

philip.joebstl
Posts: 26
Joined: Tue Oct 09, 2012 12:56 am

Re: LINQ to dataset

Post by philip.joebstl »

Hi Mark,

I somehow didn't notice that these extension methods are not supported in CF.
As always, thank you for the quick answer!
Best regards,
Philip Joebstl

Patrick Hall
Posts: 22
Joined: Fri May 25, 2012 7:44 am
Location: Charlotte, NC. USA

Re: LINQ to dataset

Post by Patrick Hall »

According to Microsoft "Version Information" Section they are supported in Compact Framework 3.5, but you must add a reference in your build process to the System.Data.DataSetExtensions.dll. This isn't included in iX Developer projects by default... Have you tried adding the Assembly Reference Manually? You should still only add the single using in your script though...

Code: Select all

using System.Data;
Referenced Assembly Ribbon
Referenced Assembly Ribbon
ReferencedAssemblyButton.png (47.62 KiB) Viewed 14164 times
Then Browse for the Assembly in the Compact Framework SDK Folder.
Assembly Reference Browser
Assembly Reference Browser
AddAssemblyReference.png (136.17 KiB) Viewed 14164 times
Referenced Assemblies
Referenced Assemblies
UpdatedAssemblyReferences.png (24.95 KiB) Viewed 14164 times
System.Data will then reference the System.Data.DataSetExtensions.dll and should allow access to the AsEnumerable() member.

When I do this I can build successfully without error, but... I can't confirm it will work on a T7A and T7B (because I have not downloaded it to a real device, only checked that it will build), though you should be able to test that by downloading your resulting project.
Best Regards,
Patrick Hall

Post Reply