Click here to Skip to main content
12,898,335 members (55,270 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 9 Nov 2011

LINQ is for querying! Not for manipulation.

, 5 Dec 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Notes regarding LINQ abstraction.

LINQ is all about querying data, not manipulating data.

Manipulate data means to change the data, for example:

List<string> lst = new List<string>();
lst.Add("1"); //this line is changing(manipulate) lst

An example of querying data:

List<string> lst = new List<string>();
var res = lst.where(s => s.StartsWith("1"); //this line is NOT modify lst

Query data is mostly used by using restriction and Projection operators

So now, after we have clarified the distinction between manipulating and querying, let us understand the motivation behind each..

Well, the answer is that LINQ extends IEnumerable*, and IEnumerable is readonly! Therefore manipulating data with IEnumerable will break the abstraction of it.

Then you might ask, why does LINQ extend IEnumerable and not other interfaces which allow to manipulate data?

This is beacause it allows LINQ query operators to be cohesive and focus on the main goal which is to query data.
LINQ operators don't care if the collection is readonly or not, adding new functionality to manipulate data will break this abstraction.

The discussion of why LINQ extends IEnumerable/ the benefits and disadvantages of it, is a much wider topic, which I am going to leave open for now..

I leave it to you to wonder why extending IEnumeurable supports the abstraction of LINQ Deferred Execution.

(*Reminder: The IEnumerator interface exposes the Current property, and the Reset and MoveNext methods.)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer GE
Israel Israel
I am Software Developer at GE company for more than 2 years,

I created since I didn't found any other good dedicate LINQ tutorial

You may also be interested in...

Comments and Discussions

GeneralProbably you did not get the idea of the functional programm... Pin
vl212-Dec-11 22:48
membervl212-Dec-11 22:48 
GeneralReason for my vote of 1 No value added Pin
ArchAngel12312-Dec-11 10:28
memberArchAngel12312-Dec-11 10:28 
GeneralRe: This tip allows you to understand better the abstraction of ... Pin
Delashmate12-Dec-11 22:14
memberDelashmate12-Dec-11 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 5 Dec 2011
Article Copyright 2011 by Delashmate
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid