LINQ

This forum is meant for examples of X# code.

User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

LINQ

Post 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 544 times
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

LINQ

Post by robert »

Phil,

Sense that makes.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4907
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

LINQ

Post by Chris »

?intellisense easier of sake the for just up everything Mix

:-) haaaN

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Otto
Posts: 174
Joined: Wed Sep 30, 2015 6:22 pm

LINQ

Post 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)
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

LINQ

Post 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
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

LINQ

Post 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
______________________
Johan Nel
Boshof, South Africa
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

LINQ

Post 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...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

LINQ

Post 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.
Attachments
AnonTypes_13.jpg
AnonTypes_13.jpg (29.37 KiB) Viewed 544 times
AnonTypes_24.jpg
AnonTypes_24.jpg (59.42 KiB) Viewed 544 times
AnonTypes_25.jpg
AnonTypes_25.jpg (77.76 KiB) Viewed 544 times
Post Reply