Sahil posted even better way to use Linq over DataTable.Rows collection than the one I blogged about. Use extension method OfType<T> (sounds like a VB.NET method) on non-generic IEnumerable and there you go.
I just updated Community Server 1.1 to CS2 beta3 and the thing looks really good. So far there were no showstoppers, just minor glitches. And obviously, posting works as expected. Good work, Telligent.
Community Server 2 beta 3 is out – I certainly hope that they’ve fixed AM/PM bug which prevented you posting anything when the server was hosted on non-us regional settings. Get it here:
Go, get Microsoft Expression Interactive Designer January 2006 Community Technology Preview (CTP) (aka Sparkle) here:
I see such questions here and there: “Is Linq going to interfere with normal C# 2.0 projects?”.
Here is my guess. There are two parts of the issue.
- Compiler. Linq needs a new C# (or vb.net) compiler which might not work as expected (as Linq is in preview phase at this time). However, the Linq compiler kicks in only when explicitly set and the setting resides in .csproj file when you create a new Linq project: <Import Project=”$(ProgramFiles)\LINQ Preview\Misc\Linq.targets” />. So, if you don’t want Linq compiler, don’t create a Linq project or replace the Import directive with this one: <Import Project=”$(MSBuildBinPath)\Microsoft.CSharp.targets” />. I haven’t tested the scenario but it should work.
- VS2005 integration. To support the syntax changes (from, select, where, …) Linq has to patch IDE – otherwise you would get errors everywhere new syntax is used. This patch doesn’t affect the final binaries thus you don’t need to do anything. Ok, I have a sense that it kills some IDE features but if you can live with that then it is ok. Otherwise you can uninstall it by running C:\Program Files\Linq Preview\Bin\Uninstall Visual Studio.IDE Support.cmd. Of course, there is also Install Visual Studio.IDE Support.cmd command located in same folder. Again, I didn’t try it yet but it should work.
The bottom line is – theoretically it shouldn’t affect C# 2 production.
While Linq doesn’t cause any evident showstoper problem you have to understand that Linq is in preview phase (not even beta yet) so I wouldn’t recommend to anyone installing Linq on production machine.
Currently you can’t directly use Linq over and DataSet/DataTable/DataRowCollection/etc. class. Trying something like this won’t work:
var q = from r in table.Rows select r;
Enabling Linq over the classes mentioned above is under consideration by Microsoft and I don’t doubt they will enable them. But if you wish to do it now, here is the simple workaround. Everything you need to do (the Linq requires) is that the class implements IEnumerable<T>. So, I will create a generic class that wraps around any IEnumerable and implements IEnumerable<DataRow>. Here is the code:
// simple wrapper that implements IEnumerable<T>
internal class LinqList<T>: IEnumerable<T>, IEnumerable
internal LinqList(IEnumerable items)
this.items = items;
#region IEnumerable<DataRow> Members
foreach (T item in items)
yield return item;
IEnumerable<T> ie = this;
The code is pretty straightforward, isn’t it. And here is a simple test:
// create and fill table
DataTable table = new DataTable();
// create a wrapper around Rows
LinqList<DataRow> rows = new LinqList<DataRow>(table.Rows);
// do a simple select
IEnumerable<DataRow> selectedRows = from r in rows
where (int)r[“Id”] == 2
// output result
foreach (DataRow row in selectedRows)
It is not pretty as it could be but it certainly works. And if you want you can create your own strong typed table implementation that exposes LinqList<DataRow> Rows property. Perhaps using a code generator such as CodeSmith instead of doing boring work yourself.
I’ll be talking about “What’s new in Visual Studio 2005/.net 2” for Microsoft Slovenia ISV partners. This will be a whole day event and it will take place on 19 January, 2006 at Microsoft Slovenia in Ljubljana.
I’ll be covering these topics:
- C#, VB.NET and framework
- Extending Visual Studio 200x with CodeRush and CodeSmith
Thus if you are interested in the event check out this page and look for the event entitled “Novosti v Microsoftovi razvojni platformi .NET 2.0 in okolju Visual Studio 2005“.
Language of presenting will be Slovene.
Do you think that a floppy drive is a relict from the past that you won’t need ever again? Think again:
Recently I found myself installing Windows XP 64bit edition on an Athlon 64 powered machine. The thing had also two 250Gb disks in RAID 0 and no floppy whatsoever (who needs a floppy these days anyway?). The RAID feature was provided by nForce 4 chipset. So I went installing new and shiny 64bit OS. The shock came soon: at setup boot time OS didn’t recognize nForce 4 RAID (I didn’t expect that it would) and required a floppy disk with drivers to be inserted. It won’t accept anything else than floppy. USB – no. CD – no. DVD – no. Nothing. It had to be a floppy. The same situation occurs with other Window OS flavours, including 2003. Again, who would need a floppy on a server machine? Obviously everybody that wants to install Windows with a RAID array not provided on installation CD. After googling around I found that there is an option to create an unattended setup which isn’t that easy to worth bother. So I went disassembling my kid’s computer, extracted dusty 3.5″ floppy and connected it to the thing I was installing Windows on. It took me 4 floppies to find a working one (without all sorts of errors) to copy nVidia RAID drivers. After that the install went smoothly.
The bottom line is: don’t throw away floppy drives as you might need one in the near future. Or, perhaps the hardware manufacturers might start producing floppy drives for one use only.
Developer Express recently released first beta version of their XPO2 ORM product to their subscribers (currently there are also betas of both XtraCharts and XtraLayout – all of these betas look really good). Since I’ve already dived into Linq/DLinq world I soon missed Linq features for doing queries. Thus I couldn’t resist and started implementing it myself – hence the XpoLinq project is born. Here is an example of syntax: