the Language of LINQ - Lovely !?

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the Language of LINQ - Lovely !?

Post by Phil Hepburn »

Hi Robert, Team, and guys,

Well, you know that I have been exploring the use of LINQ extensively in my test applications / applets, so now I will feed-back some useful information to you.

Firstly, I don't seem to get any issues with the compiler and my new X# code to solve LINQ related problems - those early days have gone, stuff just works ;-0)

And secondly, I have found a nice clean and clear way to use LINQ in what I call a 'cascading' way (or manner). It makes my code 'Lovely' !!!

I have listened to you guys about keeping code simple, clear, and easy to maintain in the future, and have found by defining 'multiple' queries - one based on another - that we can get good answers to more complex problems, simply by letting the LINQ system do all the complex work for us. The data selection is still done within the back-end data server, but on one query alone.

In the example I post here, I have defined FOUR simple queries which cause the LINQ system to compose and send only ONE final query to the database engine - we get one results set in return. Checkout the following image details, I will explain more afterwards :-
PearlsEF6_81.jpg
PearlsEF6_81.jpg (153.05 KiB) Viewed 253 times
In fact line 354 is the code line which triggers the LINQ system to send a query to the SQL Server, its only then that we need data - we are asking for a short list of all the Suppliers in order (large to small) of the cash / money we need to pay them for their products sold to the customers. Our .NET code should be understandable if studied carefully.

However, this is what is sent to the Server (don't panic!) :-
PearlsEF6_82.jpg
PearlsEF6_82.jpg (106.64 KiB) Viewed 253 times
Yes, even those guys experienced in SQL statements will have their eyes water just a little ;-0)

However, it works and gives us what we need, as can be seen in the next image :-
PearlsEF6_83.jpg
PearlsEF6_83.jpg (27.26 KiB) Viewed 253 times
Yes, one code line calls the STATIC method which finds the list of four Suppliers. It would appear to me, and my not very clever test data, that the results / answers are correct.

I have recently (today / yesterday) created quite a few similar business related STATIC methods to find out interesting facts about my simple 'Stock' system. I am finding that all the code I am writing is in fact query LINQ code, and I am using extensively .NET collections. Yes, anonymous types are used within my query definitions and this makes life both simple and clean. I am thinking entirely in 'Entities' and not Tables. Rows and Columns are out and Objects and Properties are definitely 'in'.

I now have some nice session material for Cologne if the two 'M's will let me present it.  

I have learned a lot, and find X# great to use for this sort of LINQ and EF6 work - brilliant! I never thought I would see the day I could do this in xBase - thanks to Roslyn it is now possible.

Well done Team - have a break over the Festive Season ;-0)

Seasonal wishes to all,
Phil.
Wales, UK.
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

the Language of LINQ - Lovely !?

Post by NickFriend »

That second image sums up perfectly why I hate SQL and love Entity Framework and Linq!!!

Merry Christmas!

Nick
Post Reply