Page 1 of 1

LINQ to dataset

Posted: Thu Sep 05, 2013 2:11 am
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!

Re: LINQ to dataset

Posted: Fri Sep 06, 2013 11:07 am
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 15150 times

Re: LINQ to dataset

Posted: Tue Sep 10, 2013 8:23 am
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!

Re: LINQ to dataset

Posted: Tue Sep 10, 2013 12:27 pm
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 15122 times
Then Browse for the Assembly in the Compact Framework SDK Folder.
Assembly Reference Browser
Assembly Reference Browser
AddAssemblyReference.png (136.17 KiB) Viewed 15122 times
Referenced Assemblies
Referenced Assemblies
UpdatedAssemblyReferences.png (24.95 KiB) Viewed 15122 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.