Posts Tagged ‘.NET 3.5’

TechEd Developers 2007 in retrospect – Wednesday

Monday, November 26th, 2007

Wednesday at TechEd was another "linqy" day for me. In the morning I joined the session "LINQ to XML", with speaker Mike Taulty. With LINQ to XML there is a new XML-API as Part of .NET 3.5 which sits in the namespace System.Xml.Linq. LINQ to XML makes it easy to create and edit XML documents without using additional syntax like XPATH or XSLT, but, of course, LINQ to XML won’t replace the existing APIs implemented in classes like XmlDocument, XmlReader, XmlWriter or XPathNavigator. It’s just another XML-API that let’s you use LINQ queries on top of XML.

Mike Taulty showed that LINQ to XML is much closer to XML than the other XML-APIs as part of the .NET Framework. When you create a XML-document with the new API, you can see that your C#-Code is really close to the XML (if you format your code like below and additionally put the XAttribute-Elements on the same line as the XElements they belong to (I hadn’t enough space to do so :-))):

XDocument doc = 
  new XDocument(
    new XElement("TrivadisLocations",
      new XElement("Location",
        new XAttribute("City","Basel"),
        new XElement("Consultants",
          new XElement("Consultant",
            new XAttribute("FirstName", "Thomas"),
            new XAttribute("LastName", "Huber")
          ),
          new XElement("Consultant",
            new XAttribute("FirstName", "Christoph"),
            new XAttribute("LastName", "Pletz")
          )
        )
      ),
      new XElement("Location",
        new XAttribute("City", "Freiburg"),
        new XElement("Consultants",
          new XElement("Consultant",
            new XAttribute("FirstName", "Thomas"),
            new XAttribute("LastName", "Wukasch")
          )
        )
      ),
      new XElement("Location",
        new XAttribute("City","Zürich"),
        new XElement("Consultants",
          new XElement("Consultant",
            new XAttribute("FirstName", "Patrick"),
            new XAttribute("LastName", "Spieler")
          )
        )
      )
    )
  );

doc.Save("locations.xml");

The XML generated from the code above looks like this:

<?xml version="1.0" encoding="utf-8"?>
<TrivadisLocations>
  <Location City="Basel">
    <Consultants>
      <Consultant FirstName="Thomas" LastName="Huber" />
      <Consultant FirstName="Christoph" LastName="Pletz" />
    </Consultants>
  </Location>
  <Location City="Freiburg">
    <Consultants>
      <Consultant FirstName="Thomas" LastName="Wukasch" />
    </Consultants>
  </Location>
  <Location City="Zürich">
    <Consultants>
      <Consultant FirstName="Patrick" LastName="Spieler" />
    </Consultants>
  </Location>
</TrivadisLocations>

OK, of course, writing XML is not such an amazing thing if you have a query language like LINQ. Reading XML would be more exciting. So let’s say you want to read the XML-file we’ve just created above and you want to get out each location-City where a "Thomas" works. You can just load the document by calling the static Load-Method of the XDocument-class and create a query on top of that document:

XDocument doc = XDocument.Load("locations.xml");

var query = 
  from c in doc.Descendants("Consultant")
  where c.Attribute("FirstName").Value == "Thomas"
  select c.Ancestors("Location")
         .Attributes("City").First().Value;

foreach (string city in query)
{
  Console.WriteLine(city);
}

The Output on the Console is
> Basel
> Freiburg

With the query above you get the cities more than one time if there are more than one “Thomas” in one location. Fortunately the XML above has exactly one or none in each location. By using a simple group by you won’t get any cities more than one time, even if there are more than one “Thomas” in a location:

XDocument doc = XDocument.Load("locations.xml");

var query =
  from c in doc.Descendants("Consultant")
  where c.Attribute("FirstName").Value == "Thomas"
  group c
  by c.Ancestors("Location")
      .Attributes("City").First().Value
    into grouping
    select grouping.Key;

foreach (string city in query)
{
  Console.WriteLine(city);
}

In the afternoon I joined the Session "Entity Framwork: Application Patterns", with speaker Pablo Castro. If you’ve already had a look at the Entity Framework, maybe you were just thinking about the DataContext class. What is it with this class? Do you keep it in a stateful DataAccessLayer, or is it stateless and you create it each time the BusinessLayer accesses you DataAccessLayer? Pablo’s answer is that it’s stateless. The DataContext knows the structure and metadata of the underlying database, but it has no state and it is very thin. So in every method like "GetCustomerById(Guid customerID)", you would create a new instance of the DataContext. Normally you would create the DataContext in the header of a using-block, so that it’s automatically disposed at the end of that block.

TechEd Developers 2007 in retrospect – Monday

Wednesday, November 14th, 2007

Last week I went to Barcelona for five days, participating at TechEd Developers 2007 (05. – 09. november). In the following posts I’ll just show you a short summary of my experience at TechEd Developers 2007. Let’s start on Monday.

On Monday the Keynote-Session started after a life grafiti-show with some really breaking news presented by S. Somasegar (Microsofts Corporate Vice President of the developer division):

  • Visual Studio 2008 and .NET 3.5 will be available to MSDN subscribers by the end of November
  • The first CTP of Microsofts Sync Framework is available now
  • For those of you using Microsoft Popfly, a new Popfly Explorer will be available
  • This year there will already be a CTP of the next Version of Visual Studio, called “Rosario”. In 2008 there will be a Beta of it

That are great news, especially the release of Visual Studio 2008 before the end of November. In fact Visual Studio 2008 really differs from the Visual Studio versions we had before. It’s the first time you can build applications that target different Framework Versions. With Visual Studio 2008 you can build applications that target .NET 2.0, .NET 3.0 or even .NET 3.5. This feature is called Multi-Targeting, and its possible, because .NET 2.0, .NET 3.0 and .NET 3.5 are all using the same Common Language Runtime, the CLR 2.0 that was introduced with .NET 2.0. Of course another great feature is the possibility to debug into the .NET Framework source code. A great possibility to learn some new best practices and to look how Microsoft has done it

The Microsoft Sync Framework is a new platform for enabling roaming, offline and collaboration across your applications, services and devices. The Framework also contains built-in support for synchronizing relational databases, NTFS and FAT file systems, etc. Get some more infos and the first CTP of it here.

After the Keynote-Session I joined the Session A Tour of Visual Studio 2008 and the .NET Framework 3.5, speaker Daniel Moth. Daniel explained that the .NET Framework 3.5 is a superset of .NET 3.0 (and so still uses the CLR 2.0). He showed some great features of the new IDE, like the new refactoring features added to the contextmenu in the codeeditor, or the transparency-feature for the intellisense-Window. You can make the intellisense-Window transparent by pressing the Ctrl-Key. So you can look at your code while leaving the intellisense-window open. Daniel also explained the terms of the green and red bits in a really good manner. Green bits are those assemblies that are new in .NET 3.5, and haven’t existed in .NET 3.0. Red bits are those assemblies that already existed in .NET 3.0, but are lightly extended and fixed with an installation of .NET 3.5. The Red bits are called “red”, because they describe a difficulty. If your .NET 3.0 application takes advantage of a not well implemented feature (maybe call it a bug :-)) in .NET 3.0 and that bug will be fixed with .NET 3.5, your application won’t work correctly anymore when you change this bug/feature by installing .NET 3.5. So microsoft has to be very careful with the red bits that are shipped as part of .NET 3.5. From the green and red bits you could also conclude something about the installation of .NET 3.5:

  • If you have .NET 3.0 already installed, an installation of .NET 3.5 will use this existing installation and change the red bit assemblies (some existing .NET 3.0 assemblies) and add some brand new Assemblies (the green bits). That means, after the installation of .NET 3.5 you wont come back to .NET 3.0, but every .NET 3.0 application should run well on .NET 3.5 (if Microsoft has done a good job with the red bits)
  • If you haven’t .NET 3.0 installed, an installation of .NET 3.5 will install whole .NET 3.0, plus the red and green bits of .NET 3.5

As the last session on Monday, I joined the session A Windows Communication Foundation (WCF) Walkthrough using Visual Studio 2008, but it wasn’t really as amazing as I thought before. The only new stuff for me about WCF I got out of this session were the things that ship with Visual Studio 2008, but nothing about WCF itself. In Visual Studio 2008 there will be new Project-Templates to generate a WCF-Library and a new UI that allows you to test your services easily.

In the evening, the “Ask The Experts” was open. The first thing I was looking for was an “Ask The Experts to WPF”-stand. But I didn’t find one. There were stands with experts in Visual Studio 2008, SQL Server, BI, Office, Silverlight and Expression and many more, but no stand with experts in WPF. So I just went to the Silverlight stand and asked for the WPF stand. The guy pointed to another person and said: “He asked me exactly the same questions 10 seconds ago, unfortunately there is no stand with WPF-experts”. And the other person said, “Some questions about WPF?”. Yeah, I thought, here I was right. Looking at his name, I recognized the name of the person and I knew, here I’m really right. It was Ian Griffiths, author of the very first WPF-book, “Programming WPF”, currently in its second edition. We spoke about nearly 1 hour about developing real enterprise applications with WPF, about the WPF-Designer in Visual Studio and about using Blend for designing your app. In most cases, Ian and I had the same opinion, and we both are waiting for the datagrid as part of .NET/WPF. :-) Today there are only third-party-grids available from famous control authors like those from Infragistics. Even in .NET 3.5 and WPF 3.5 (it’s really called WPF 3.5 and not WPF 1.5), Microsoft introduced no more 2D-Controls. But WPF 3.5 contains some new 3D-Elements like UIElement3D or Viewport2DVisual3D, that receive Input Events and make interactive 3D much easier than in WPF 3.0.