fbpx
Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1

TOPIC: the Language of LINQ - Lovely !?

the Language of LINQ - Lovely !? 2 years 7 months ago #882

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
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 :-



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!) :-



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 :-



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.
Attachments:

Please Log in or Create an account to join the conversation.

the Language of LINQ - Lovely !? 2 years 7 months ago #883

  NickFriend's Avatar NickFriend Offline Posts: 205
That second image sums up perfectly why I hate SQL and love Entity Framework and Linq!!!

Merry Christmas!

Nick

Please Log in or Create an account to join the conversation.

  • Page:
  • 1