March 2009: For more information see the latest article on FLEX & LINQ:
I had certainly delayed looking at LINQ for too long.
After seeing a screencast on some of the new features in ASP.NET I noticed the very handy LINQ to SQL item.
Let’s just say I’m not using strongly typed datasets anymore.
LINQ provides strongly typed access to your database (tables, views, sprocs and function) while also allowing you to query those results.
Whilst many still advocate the use of stored procs for larger and more advanced or intensive queries, at least some of the simple overhead can be reduced. Furthermore, updating your C# classes to reflect your DB is as simple as updating the LINQ to SQL item.
But the major advantage from a Flex remoting perspective is how easy it is to have all this returned data in your client.
Say I have three tables: (already linked with relationships via foreign keys)
Employee, Company & Position
I add the LINQ to SQL item to my solution. Inside, I connect the LINQ object up to the db and drag in my database objects. Voila, I have the strongly typed classes: “Employee”, “Company” and “Position”. None of this DataRow, DataTable, DataAdapter business.
Using LINQ syntax, I can do simple queries on the spot, like:
DataClassesDataContext db = new DataClassesDataContext();
var data = from e in db.Employees where e.CompanyID == someCompanyID select p;
List<Employee> employees = data.ToList<Employee>();
Now, I can return this list to either FluorineFx or WebORB and the ArrayCollection that the List is serialised into will contain an array of Employee Value Objects (my Employee.as file). Nothing special there.
BUT, the “Company” property is also provided. This is the Company property that is automatically generated in LINQ to SQL that provides the foreign key reference to the company.
This holds for all your foreign keys.
So if you want to reduce your overhead from a C# (writing classes for your db objects) and DB perspective (writing sprocs for every data call), then take a gander at .NET 3.5.
- If you weren’t aware, .NET 3.5 framework is actually an addition to .NET 2.0. This means that once you install the framework on a machine, no manual IIS settings are required (as opposed to the 1.1 to 2.0 switch) to activate 3.5 on a website or virtual directory.
- Both FluorineFx and WebORB support .NET 3.5