Running on Community Server 2 beta3

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.

Is Linq going to interfere with normal C# 2.0 projects

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.

  1. Compiler. Linq needs a new C# (or 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.
  2. 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.

Linq over DataTable.Rows

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
        IEnumerable items;

        internal LinqList(IEnumerable items)
            this.items = items;

        #region IEnumerable<DataRow> Members
        IEnumerator<T> IEnumerable<T>.GetEnumerator()
            foreach (T item in items)
                yield return item;

        IEnumerator IEnumerable.GetEnumerator()
            IEnumerable<T> ie = this;
            return ie.GetEnumerator();

The code is pretty straightforward, isn't it. And here is a simple test:

  // create and fill table
  DataTable table = new DataTable();
  table.Columns.Add("Id", typeof(int));
  table.Rows.Add(new object[]{1});
  table.Rows.Add(new object[]{2});
  table.Rows.Add(new object[]{3});
  // 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
         select r;
  // 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.

One day presentation of &quot;What's new in Visual Studio 2005/.net 2&quot;

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
  • Debugger
  • Extending Visual Studio 200x with CodeRush and CodeSmith
  • WinForms

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.

Is floppy disk drive dead? Apparently not.

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.

Building XpoLinq

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:

RhCollection<Address> address = from a in addresses where a.City == "Nova Gorica" select a;
Note that Linq is used only for creating select expressions while behind the scenes runs XPO2.
XpoLinq syntax and has few benefits over existing Xpo CriteriaOperator syntax:
- intellisense support (a.City)
- code checking during compile time
- integrates with Linq (you can mix queries between Xml, DLinq, XLinq and any other Linq compliant subset)
I find all of these points above extremely useful features that should be present asap in any product that does queries. Perhaps the only problem is that Linq is still far away to being released (but it is very functional right now) and using its features for short time projects might be risky. Anyway, whether I continue work on XpoLinq is unknown depending on several factors: my time, DevExpress implementing it, my curiosity, etc. Regardless if my XpoLinq lives or not it has been certainly an interesting Linq learning experience.