Linq To SQL : LinqContext per Unit of Work

11 11 2008

To implement a Linq To SQL Oriented solution, there are many ways to construct your application. But only one interested me : the Context per Unit of Work Architecture.

When using Linq To SQL, you need to instanciate a Context which contains your entities tables and allow you to apply query methods. But when your application is construct with many layers, you only can pass Context through methods to keep the same context during your business operations. It is the same problem when a transaction is required(managed by Linq To SQL Context though optimistic transaction).

Read the rest of this entry »

Linq To SQL Generic Controller

20 10 2008

With the power of Linq language, it’s easy to use Linq To SQL to build 95% of the data access interrogation.

But you will notify that 2/3 of your data access methods is always the same, as GetById, GetAll, Insert, DeleteById…

So Microsoft staff has written a class named GenericController that allow you to centralize all standard methods in one class. You only need to inherit from it and a good part of your job is done.

If you look more deeper in this pack, you will find some other classes written to instanciate one LinqContext by Query or a Linq To SQL Debugger(see also my ticket on DebugWriter).

Linq To SQL : How to order with a string typed expression ?

23 09 2008

After using Linq To SQL queries, I was quickly confronted to sort my data with a string expression provided, for example, by a gridview when a user require it. At this moment, I understood that the strongly typed system used with Linq cannot help me for this task… Understanding the fact that allowing a string expression representing an object property is contrary to Linq purpose, I began to search with our best friend “Google” a soluce to resolve quickly my problem. But the best that I can obtain was a “switch case solution” which, according to the string property name, build the linq query sort filter with the associated object property. Immediatly, I guess my switch case code with 8-10 columns… No…

So, I started to write an extended method “OrderBy” allowing to take a string sort expression. Here the result.

Read the rest of this entry »

Linq Overview

23 09 2008

During my migration from .NET 2.0 to .NET 3.0/3.5, my first tought was : ‘With .NET 3.5, I can used Linq To SQL and stop to bore me with all the code generation tools”. I don’t want to crush the glory of tools like Raptier or Code Smith, but an ORM produce by Microsoft can be better in generation time(class generation and integration) and simplicity. It was true(for common uses). But better than that. Linq offers many others functionalities(strongly typed, composite queries, relashionship between objects and many more). And I began to forget all about others problems when the Graal was not here…

After a month of research, I have started to write a document on my Linq feedback and I share it today 🙂