Envisage a situation where, there are 20 people in a room and all of them are from diverse places. They don't understand any common language and now – you've to address them. Same ways, now visualize, there are many different platforms – which doesn't have anything in common – and you need to build one solution which will run on all of these platforms. Well, there are many ways to handle these kind of scenarios. You can call translators/interpreters OR ask everyone in the room to learn, English. The second option looks logical. In case of different platforms – we already have solutions as Sun J2EE OR Microsoft .NET. These technologies provides an abstraction layer like mechanism, to write code on one platform, which can run on other platform.
Now, we have handled these 20 people scenario and different platform scenario – but world doesn't end over here.
There are many issues with traditional systems and LINQ tries to surmount them. Lets understand those issues first, so we'll know WHY we need LINQ.
- As we all have some familiarity with software application development we comprehend that every software we develop, deals with data. This data can be in any form – it can be variables, array of variables, files OR file system, databases OR data-stores, Windows Management Instrumentation (WMI) Store, web services and what not. Now, even this can become more finicky like, whether its NTFS File System OR FAT32? Whether its SQL, Oracle, MySQL database? Whether its XML or a simple Access File or flat file? And as we know, dealing with different technologies means learning it from scratch – once again. If we want to access data from files, we need to learn file system APIs. If we want to access data from SQL Database, we need to learn data access APIs contained within ADO.NET. Likewise, different APIs for different technologies. So the first annoyance with dealing with software development is – learn different data access APIs related to different data access technologies.
- Even though, we have ADO.NET, to access data from various data-sources, the APIs deals with connections , tables, rows, columns, records, but languages that we use deals with Objects. So, both database systems and programming languages have different paradigm of programming. This in short means a lot of niggling stuff between database and programming languages.
- Developers, by default, are master in a particular language. It can be C/C++, C# or someone will be like me who simply loves VB. All of these languages have different syntax. Many times, it's not possible for developers to learn all these languages OR master their syntax. And learning a new language is a big task. It becomes tedious to learn different languages which deals with data like T-SQL in general and learn another language which deals with objects.
- Now, as we deal with different data sources, we need to deal with data-type mismatch. The length of string in SQL Server will be different than that of in C# likewise there are many more different data types and suppose we change database server (from Oracle to SQL Server) then it becomes more hectic as we might need to change almost all portion of Data Access Layer (if system architecture is not designed to deal with it) hence many data sources and object oriented languages have different set of data-types.
Like these, there are many issues with existing systems when we talk about accessing OR manipulating data. LINQ tries to overcome all these limitations by providing
- Uniform mechanism for dealing with any data source – whether its Array, SQL Server Database, XML Dataset, XML file, or any other data source
- Object-Relationship Mapping – which maps tables in database with Objects in applications
- Language Integrated Support – syntax for accessing/manipulating data is integrated with your favourite language.
There can be numerous advantages to LINQ – but as per my point of view (OR as developer point of view because I'm also a developer J) these three are the major advantages of LINQ.
In next few posts – I'll explain how we can use LINQ in our applications i.e. a practical approach.
Happy Coding | Mayur Tendulkar