Aline’s Tech Blog

All my geekness is here :-)

First steps with LINQ December 4, 2008

Last week, I had to think about LINQ for my project at work, and I discovered all the power of this framework. I didn’t go further than a very basic sample demo. Here are my first thoughts about this technology, after only a few hours surfing the net and trying a little things. (forgive me for my mistakes and lack of experience, though.)

A powerful Database-to-classes mapper

Several possibilities:

  1. You are using an existing database or you prefer designing your database before your object model: Create a new SQL connection in Visual Studio 2008 and drag-n-drop your database in a new DBML file… That’s all, everything is done and you can manipulate objects.
  2. You are starting a new project… you will work with only 1 model / diagram: the DBML file.

Something which could be useful if you want to create a database from the DBML : The db.CreateDatabase() feature. But be careful, as he says.

An easy and secure way to query data

Here you cannot forget a string query somewhere. You write your query using visual studio Intellisense, you cannot make mistakes…

Easy to use, fast, smart… magic!

In 5 minutes the mapping, the data abstraction is done. So easy. Nothing else to do. I think if I was designing a new project now, I would not hesitate.

LINQ allows anyone to have a good structure in his application by creating an adaptable data access layer.

Limits

Full-Microsoft… Again

What I only found about LINQ was LINQ to SQL (understand MS SQL SERVER) and LINQ to XML. Nothing for other database management systems for the moment.

Not serializable

This can look like a minor problem, but the LINQ tables and data is not serializable. And then, no .NET remoting with LINQ! But of course, the new .NET 3.5 WCF framework works with it.

I’d like to make further topics about LINQ. Probably 1 sample demo explained, and LINQ vs NHibernate.

 

WPF Data Templates: Several views for 1 class July 28, 2008

Filed under: WPF — Aline @ 10:00 am
Tags: , , ,

Today i’m going to introduce you a WPF concept called Data Templating.

When I started WPF, i felt lost, and i didn’t know how to do. I wanted to use my scholar knowledge about object-oriented programming, make inheritance relationships between usercontrols, like in windows forms or Java.

My problem was that I had 1 user control (basically, a grid with several labels), which displays the contents of a collection in the labels. My graphic control had to be used in different configurations. Depending on the configuration, the data was not displayed in the same way, but the business code (data collection, grid) was the same.

The first idea i had, using my little UML model, was to make inheritance: a parent grid user control, with several children chosen depending on the configuration. In this way, with WPF, everything was coded into a .VB file. It was quite inappropriate. Moreover it was hard to realize this inheritance, because WPF didn’t allow me to display my parent Grid control into the designer…

And then, I posted on MSDN forums, WPF disciples, I started reading this book, and understood i wasn’t thinking the right way.

The right way, for this particular case, is to use Data Templates.

Data Templating allows you to have 1 class that contains all your business code (here, my data collection), and to consider your graphic interface as a template (here a grid template), that you define in a resource dictionary.
This is very easy to do this with Expression Blend. You can define several templates to apply them to the class.

After this you can define a Template Selector class to select your template programatically, or select it dynamically. The data template for a custom user control is defined by the ContentTemplate attribute. In my solution, i have bound this attribute to the selected item of a combobox.

The template elements (labels,…) can be bound (in xaml ResourceDictionary) to the collection items. And the graphics can be completely different.

To use data templates, here are some cool links which helped me a lot, including code samples and HowTos:

http://msdn2.microsoft.com/en-us/library/ms752339.aspx
http://www.contentpresenter.com/index.php
http://msdn.microsoft.com/en-us/library/ms742521.aspx

 

Custom persistence with custom tracking (vb.net source code) July 1, 2008

Filed under: WF — Aline @ 8:37 pm
Tags: , , ,

This first article aims at presenting a very simple solution for custom persistence and tracking services for windows workflow foundation.

The solution presented here has been designed to run with a long-running state machine workflow but could be adapted to any use case. It contains:

  • A persistence service that stores the serialized workflow into a binary file,
  • A tracking service that stores the state changes into a text file.

This article will only explain how to create and use persistence and tracking services. A more detailed explanation about a simple state machine workflow running with a host demo application will be done in a further article.

(more…)