Advantages of using language integrated queries technology.
Mitter, Florian ; Stopper, Markus]
Abstract: Current object oriented programming languages require
additional application programming interfaces (API's) to access the
stored data in relational databases. Therefore an investment of
learning-overhead is necessary. Additionally missing compiler support
and IntelliSense feature do not simplify the situation as well as the
case for doubling-up possible error sources regarding to be on the way
in two worlds. A combination of features in upcoming Microsoft C# 3.0
(generics, anonymous delegates, lambda expressions, query
expressions--LINQ) can achieve the desired goals without facing these
disadvantages. While in beta phase this solution lacks usability, but
Microsoft company announced to implement LINQ in Visual Studio 2008
(Codename Orcas) with many more upgrades like a control element for an
appropriate data source. Substitutional there are different object
relational mappers available that image database tables in objects, but
if the company's development progress will be as expected, after
all LINQ technology would be the most effective solution for the
creation of data driven applications.
Key words: language integrated query, generic query syntax, compile
time syntax checking, .net framework technology.
1. INTRODUCTION
Language Integrated Query (LINQ) and in particular LINQ to SQL (DLINQ) reduces the complexity to access relational data by enabling
direct data access in form of objects, attributes and methods. LINQ will
be a native part of C# 3.0 and VB 9.0 in the next version of Visual
Studio which development code name is Orcas (.NET FDC, 2007). It will be
an integrated part of .NET Framework 3.0 and might get additional
enhancements (like control elements etc.) in further patches and
releases.
2. STANDARD OBJECT TO SQL CONVERSION
To run a database query out of a programming environment, an
appropriate command string has to be assembled, which is then executed
by specific methods of superior technologies (ODBC, DAO, OLE DB, ADO or
ADO.NET). Each of them has its own object model, syntax and dependencies
to other components and libraries (Sceppa, 2006). But they have in
common, that the returned amount of data rows can be stepped through by
a pointer (per next-function). To enhance performance for multiple use
of the same query (in a loop) also state parameters can be specified. In
this case, the query can be precompiled and only the parameter will be
changed before every execution. But all in all, none of these ways is as
flexible as it ought to be.
3. PROBLEMS OF CONVENTIONAL METHODS
The conventional methods of data access have their entrapments
during the development process. In many cases the developer has to take
care of problems that should have been handled by the supporting
environment. These are simple problems like data type conversion and
string concatenation on the one hand and lack of usability (no
IntelliSense/Wizard) on the other hand. In brief, the developer needs to
know about an extra technique and its shortcomings as well as the
outcome are exposed unnecessary mistakes that could not be ignored. The
former mentioned technologies should have been database independent. Due
to this disadvantage all classic solutions simply implement a query
string. But as soon as return values occur they have to be separated and
stored in different variables of appropriate data types for further
handling. The navigation through the received data rows has to be done
by a pointer. This pointer (or cursor) has several very important
attributes. For example a forward-only cursor is of course much faster
than a dynamic cursor, but the programmer is subordinated to some
restrictions that he has to keep in mind. In general, it is a trade off
between performance and flexibility in application design. For a
following update, the values need to get concatenated back into the
right format. Editing persistent data out of a programming language
therefore requires nearly as much additional effort as the underlying
read/select operation. Grabbing persistent data this way is like an
impurity in a programming language. This is why possible errors can not
be spotted by the compiler before they happen during runtime.
4. APPLICATION AREA OF LINQ
Currently DLINQ is in beta phase and therefore it only supports MS
SQL Server. While this deficit will get remedied, another one might
still occur. LINQ does provide data manipulation language methods, but
no form to run data definition language or data control language.
Assuming that for the final version too, later changes on the database
scheme have to be implemented manually in the already existing object
model, bearing in mind that this might result in a complex task. Next to
DLINQ, which is constricted to SQL server at the moment, there are
related methods to access data out of XML (XLINQ) or even any object,
entity or array that is able to fit into the IEnumerable data type. Like
mentioned earlier LINQ is still in development. Components might take
their time until they are bug-free and several wizards still would be
necessary to improve usability (Channel 9 Forums, 2007).
5. LANGUAGE INTEGRATED QUERIES
[FIGURE 1 OMITTED]
DLINQ provides an SQL like syntax to select, group and sort data
out of a relational database but also to add, alter and delete it. One
entity class has to be created for every database table and this class
has to contain a private attribute for each table column. The existing
class "DataContext" provides an interface to a database
management system which is assessed by a connection string. The emerging
object can be used to access the database tables for reading or editing.
Because LINQ is a native part of all .NET languages, it is able to
provide IntelliSense. Additionally the compiler can assure the
correctness of the query as the code compiles (ADT, 2007). Figure 2
shows a C# code example that runs against an array and figure 3 shows
the result of it.
[FIGURE 4 OMITTED]
6. BLINQ
BLINQ is a tool that automatically generates ASP.NET websites based
on an SQL server database. Such a website then contains pages to search,
edit or insert data into each table of the underlying database.
Additionally existing data rows can be deleted as long as relational
integrity does not prohibit. BLINQ is mentioned in this paper because it
uses LINQ just the way a programmer would do. The needed entity classes
for the tables are built automatically and several ASP files are
generated for each of them. Before BLINQ can be used, the
programmer's environment has to be patched of course, since it is
not included in any ordinary framework. After this is done, the
connection string to a database is needed, and seconds later BLINQ
constructs a whole linked website, mapping the database model. This
website can easily be improved by login functionality or other useful
features, and also the style sheet is easy to change. The database
column names label the form fields of the front-end, so these labels
should get renamed in Visual Studio. A bit of additional work appears
when the database uses numeric values as primary keys instead of real
data. In this case nearly every relation in a database model has to be
altered in the website. But as long as the programmer knows where to go
to, it will not take long. Figure 6 shows a foreign key field how it is
generated by BLINQ offering the numeric value to select. Figure 7 shows
what the programmer should make out of it. This was achieved by simply
changing the DataTextField attribute of the drop-down-list to the column
name that should be visible instead of the numeric value of the country.
As can be seen in figure 7, the sorting inside a drop-down-list or a
grid view is not attained yet. Therefore the programmer needs to dig
into the code a bit more.
[FIGURE 6 OMITTED]
[FIGURE 7 OMITTED]
7. CONCLUSION AND FURTHER RESEARCH
LINQ raises the impression (further development assumed) to solve a
big and wide spread problem: the paradigm change between relational and
object model. Now that object oriented programming has already reached a
stable point it is only a question of time when the according data
access methods would get thought over (Stopper & Angerer, 2000). The
more followers this new technology will get, the more time and cost will
be invested by the programming industry and the usability as well as the
performance of emerging competitor products will arise. Even now there
exist object to relational mappers of other originators (e.g.
Hibernate). The deficit of these is simply that they are not embedded in
any programming language.
8. REFERENCES
.NET FDC, Framework Development Center (2007). The LINQ Project,
Available from: http://msdn2.micosoft.com/enus/
netframework/aa904594.aspx Accessed: 2007-09-06
ADT--Application Development Trends (2007). Anders Hejlsberg on
Project LINQ, Available from: http:// adtmag.com/article.aspx?id=20451
Accessed: 2007-09-06
Channel 9 Forums (2007). Chatting about LINQ and ADO.NET Entities,
Available from: http://channel9.msdn.com/Show
Post.aspx?PostID=202138#202138 Accessed: 2007-09-16
MS ASP.NET (2007). The sandbox projects--Blinq prototype, Available
from: http://www.asp.net/downloads/sandbox/ blinq/ Accessed: 2007-09-16
Sceppa, D. (2006). Developers book--ADO.NET 2.0, Microsoft, ISBN 978-3-86063-541-4, Microsoft Press, Redmond, Washington
Stopper, M. & Angerer, B. (2000). An Automatic Streaming
Service for Open Data Exchange in Factory Automation Systems using XML,
Proceedings of the 4th International INES Conference, 17-19 Sept. 2000,
Portoroz, Slovenia
Mitter, F[lorian] & Stopper, M[arkus] *
Fig. 2: C# LINQ example
using System;
using System.Query;
using System.Collections.Generic;
class app {
static void Main() {
string[] cities={"London", "Paris",
"Madrid", "Berlin", "Vienna",
"Vaduz", "Budapest", "Dublin"};
IEnumerable<string> expr =
from c in cities
where c.Length == 5
orderby s
select s;
foreach (string item in expr)
Console.WriteLine(item);
}
}
Fig. 3: Result of code shown in Fig. 2
Paris
Sofia
Vaduz
Fig. 5: BLINQ command line
blinq /t:c:\CapitalCities /server:localhost
/database:dbCapitalCities /user:usr1
/password:pwd1 /namespace:CapitalCities
/vDir:CapitalCities /pageDataSource