Posts Tagged ‘WPF’

TechEd Developers 2007 in retrospect – Tuesday

Saturday, November 17th, 2007

On the second day at TechEd, the first session I joined had the title "Cool Looking 3D visualizations with Windows Presentation Foundation (WPF)" (Speaker: Dennis Vroegop).

The WPF has a "built-in" 3D-API, and this session showed what you can do with 3D in your business applications. The 3D-API of WPF isn’t adequate for great 3D Games. For Games you should use Managed DirectX that has a much better performance than WPF’s 3D-API (which is build on a "Media Integration Layer" (Milcore) that is built on top of DirectX). WPF’s 3D-API is an easy way to bring some great 3D effects to your business applications. This session showed beside the basics of 3D an example how 3D can be used for a better data representation. The used example showed a 3D map and represented product-data for different locations as 3D-objects.

LINQ to SQL: Accessing Relational Data with Language was the session I joined next, speaker was Luca Bolognese. LINQ to SQL is the easiest way to access a relational database with .NET 3.5. In LINQ to SQL entity classes are mapped directly to tables in the database. For each table a class. To query a database a developer hasn’t to know anything about SQL. The query is defined in C# with the LINQ-Syntax introduced in C# 3.0. The SQL sent to the database is generated automatically. Let’s look at a very simple example to load some data.

To load data with LINQ to SQL, the first thing you have to do is to add a reference to the assembly System.Data.Linq.dll to your project and then create your entity classes. The entity classes are mapped to a table in the database via the attributes Table and Column contained in the namespace System.Data.Linq.Mapping. Of course Visual Studio 2008 contains a designer, that allows you to drag’n'drop tables from the server explorer to the designer surface, and it’ll create the entity classes for you. In this example I’ll just use a manually created class:

[Table(Name="Friends")]
class Friend
{
  [Column(IsPrimaryKey=true)]
  public Guid FriendID;
  [Column]
  public string Name;
  [Column]
  public int Age;
}

As shown above, the Class Friend maps to the table Friends as specified with the TableAttribute. You could also specify the TableAttribute without setting the Name-Property, then your classname must match exactly the table name in the database. The table Friends in the database contains the columns FriendID, Name and Age. You see exactly the same columns in the Friend class. The ColumnAttribute also has a Name-Property that you can use if your .NET field or property doesn’t match the columnname from the table in the database. The column FriendID is additionally marked as primary key. Only those fields/properties you’ve marked with an ColumnAttribute are persisted in the database and could be loaded from database via LINQ to SQL. Ok, so far we’ve created a Friend class mapping to a Friends table in the database.

Now we can already connect to the Database and query the Friends table by using the DataContext class. The DataContext is used similar to the ADO.NET Connection. In fact the DataContext constructor takes a connection string and internally uses an IDbConnection. The DataContext is responsible to translate the queries you write in LINQ against your objects to SQL. To view the SQL the DataContext has generated for you, assign a TextWriter to its Log-Property. In the following snippet I’ve just assigned the standard output stream of the console to the Log-Property of the DataContext. I’ve passed in a connection string for the database “hubethomsDB” in my local SQLEXPRESS instance to the constructor of the DataContext:

DataContext ctx = new DataContext(
  @"Server=.\SQLEXPRESS;Database=hubethomsDB");

ctx.Log = Console.Out;    

In LINQ to SQL every table is represented by a Table-Collection of type System.Data.Linq.Table<TEntity>. As the name implies, the Table itself is identified by the entity class. Back to our sample, you get a Table-Collection for the table Friends by calling the generic Method GetTable<TEntity> on the DataContext and give the Method the Friend entity as the generic argument:

Table<Friend> friends = ctx.GetTable<Friend>();

On the received Table-Collection, you can create a query in LINQ. And now there’s a big difference to SQL. The query isn’t executed by the statement you see below, it’s only created.

var query = from f in friends
            where f.Age < 30
            select f;

The query gets executed, when you iterate over it, not before!!!

foreach (var friend in query)
{
  Console.WriteLine(friend.ToString());
}

The SQL generated by the DataContext is shown in the console window below. As you can see in the generated SQL, the data is filtered on the database and not in .NET.

20071117_LINQToSQL

Luca Bolognese said in his session, that Microsoft has tried every possible query and the DataContext was able to create a good SQL statement out of it. The tests have been done by people working for long times in the sqlserver team. Time to try some real complex queries on it and check it out.

What is the benefit of LINQ to SQL, when classes are mapped directly to tables?

The biggest benefit out of LINQ to SQL is that a developer hasn’t to know anything about SQL, he can specify and execute his query directly in C#.

Conclusion: I haven’t tested real complex SQL statements with LINQ to SQL up to now. Interesting are also things like indexes used by the generated query etc.

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.