xsharp.eu • LINQ - Page 2
Page 2 of 2

LINQ

Posted: Thu Oct 13, 2016 3:22 pm
by Phil Hepburn
Hi Chris and guys,

In doing my work for a LINQ 'Click Start' eVolume a couple of years back I found this :-

Check out the image attached as I no longer have the original text to copy and paste - it explains the reason for SELECT at the end and not the beginning.
CP_selectPosition_01.jpg
CP_selectPosition_01.jpg (77.47 KiB) Viewed 579 times

LINQ

Posted: Thu Oct 13, 2016 3:37 pm
by robert
Phil,

Sense that makes.

Robert

LINQ

Posted: Thu Oct 13, 2016 5:28 pm
by Chris
?intellisense easier of sake the for just up everything Mix

:-) haaaN

Chris

LINQ

Posted: Thu Oct 13, 2016 6:14 pm
by Otto
:) but if you look at it from the extension method way, you get almost the same syntax order: you start with a collection of data (from), perform some filter on it (where) , order it (order) and create some output (select)

LINQ

Posted: Fri Oct 14, 2016 7:23 am
by NickFriend
Following on from what Otto said...

I don't know about X# but in C# you have the two different syntaxes available - query syntax

FROM Developer IN oList etc

and method syntax

oList.Where(lambda).OrderBy(lambda).ToList()

In method syntax the input into each method is the output of the previous method in the chain (so Where takes oList, OrderBy takes the result of the Where clause, etc).

Looked at that way it's all perfectly logical, aside from the reason Phil mentioned. It's only a problem if you approach it with the screwed up logic of SQL ;-)

Nick

LINQ

Posted: Fri Oct 14, 2016 7:45 am
by lumberjack
Phil and others,

I actually also think the Linq way is more logical compared to SQL.

My logic for SQL would actually be that the SELECT statement syntax is executed as a TOP to BOTTOM logic, e.g.:
FROM <table> [WHERE <tablewhere>][, <tablelist>]
WHERE <This will hold relationship constraints>
SELECT <column list>

Or from my perspective, the GROUP BY of SQL, why do you have to replicate the group by columns in the select columns?:
SELECT <key column list>, Min(<col1>), Max(Col1) --Why do we need to specify <key column list>?
FROM <table>
GROUP BY <key column list>

Instead of:
SELECT <Aggregate column list>
FROM <table>
GROUP BY <key column list>

Or if we follow a top down approach to SYNTAX:
FROM <table>
GROUP BY <key column list>
SELECT <Aggregate column list>

Just my 2c.

LJ

LINQ

Posted: Fri Oct 14, 2016 8:07 am
by FFF
NickFriend wrote:Following on from what Otto said...

It's only a problem if you approach it with the screwed up logic of SQL ;-)
Nick
Nick & al.,
never thought i might speak "pro SQL" ;) - but given that the world is full of SQL and minds that think screwed for years, it is really a typical MS solution, for ease of intellisense to invent another way of expressing things...

LINQ

Posted: Fri Oct 14, 2016 11:53 am
by Phil Hepburn
Hi George and all,

Yes, the LINQ syntax does seem a bit different at first, and particularly to SQL guys. However, I can say that once you get into LINQ it soon becomes second nature, easy, and quite likeable too.

One nice thing about LINQ is that if you then use Entity Framework 6 / 7 +, then you do not need to go back and use SQL queries ever again - just do everything from LINQ and .NET X# code.

There are also some nice features which help the standard user (which is what I class myself as), like using one query variable within another, to simplify the first query. Also, under the hood the compiler does actually turn this query syntax into an SQL statement, or query to be sent to the SQL engine when we are using EF. We can easily see the SQL statement which the compiler generates.

I found that quite often the SQL statement created and used by the compiler looks nothing much like the LINQ code I create and use. It does some very clever stuff, optimizing as well.

Are you ready for this comment of mine ? "LINQ in .NET is fun to use" ;-0)

Cheers,
Phil.