In this post I am going to show two keyword of the C# 3.0 is very helpful when playing with the set of object collection using LINQ feature.
Into
Into keyword allows creating a temporary variable to store the results of a group, join or select clause into a new variable.
Note: Into is use full when you want to perform the operation on the groped data.
Let
Let keyword allows storing the result of the query which can be used in subsequent query i.e it creates new variable and initializes it with the result of expression you supply.
Let vs Into
Most of the people find difficult which one is to use either Let or Into when designing Linq query.
Into – Hides the previous variable when used in query as you see in above example. Which means its hides previous range variable and create temporary range variable which you can use in further operation.
Let – doesn’t hide the previous variable and create new variable. Which means you created new variable and you can also use the previous variable so you can use both in the further operation.
Into
Into keyword allows creating a temporary variable to store the results of a group, join or select clause into a new variable.
var em = from e in emp
group e by new{ e.DeptId}
into gEmp
where gEmp.Count() > 1
select new { gEmp.Key.DeptId, salary = gEmp.Sum(t => t.Salary) };
In above query after applying into on groping it creates IGroping type gEmp variable, which used to apply next filter.Note: Into is use full when you want to perform the operation on the groped data.
Let
Let keyword allows storing the result of the query which can be used in subsequent query i.e it creates new variable and initializes it with the result of expression you supply.
var em = from e in emp
group e by new { e.Salary, e.Id }
into gEmp
let avgsal = (gEmp.Sum(t => t.Salary) / gEmp.Count())
where gEmp.Key.Salary == avgsal
select new { gEmp.Key.Salary, gEmp.Key.Id };
Above query is used to find out the employee(s) having the salary more than avgSalary. Let keyword allows to create new variable avgsal that used in the further operation.Let vs Into
Most of the people find difficult which one is to use either Let or Into when designing Linq query.
Into – Hides the previous variable when used in query as you see in above example. Which means its hides previous range variable and create temporary range variable which you can use in further operation.
Let – doesn’t hide the previous variable and create new variable. Which means you created new variable and you can also use the previous variable so you can use both in the further operation.
I really like this website , and hope you will write more ,thanks a lot for your information.
ReplyDelete[url=http://www.longchamp2012.com] [longchamp outlet|longchamp bags|longchamp handbags|longchamp sale}[/url]
I am actually delighted to read this website
ReplyDeleteposts which carries tons of useful data, thanks for providing these information.
my site :: website
Educational posting! Good to find somebody who really knows what they are talking about and can also produce readable blogging for us readers.
ReplyDeletewithout a doubt looking forward to your next article.
my web site: heel lifts
Great stuff to know. Thnx for posting.
ReplyDeleteA raw oniοn mау very well be гubbеd οn unbroken chilblaіns with useful enԁ
ReplyDeletereѕults. Very hot аir ballоon ridеs over the goгge are alѕo notablу сommon.
A еntire grain breakfast of previοus-fashіoned oatmeal with
almonds (grind them up to concеal them, if еssentіal) will hold a child way longer
than orаnge јuice and a bagel.
Feel free to surf to mу blog post old stone oven
Peculiаг аrticle, just what I ωaѕ lοoκing fοr.
ReplyDeleteRеѵiеω my blog post; augenoperation
ӏ woulԁ not put it in the freеzеr for a long time, you can put it in the freezer for a couple оf
ReplyDeletehours but I would not put it in thеre fοr а сouple of weeks.
After you've got the crust rolled out, transfer it to your pan or pizza stone. For several weeks I had been seeing this commercial on television telling about a new pizza and since I love pizza I decided to purchase one on my next shopping trip.
Have a look at my website; pizza pan avon lake
Мy brother suggested Ι mіght
ReplyDeleteliκe this web ѕite. He was totally right.
This post truly mаde mу day. You cann't imagine simply how much time I had spent for this information! Thanks!
my web page: blogspot.com
Post writing is also a fun, if you be familiar with then
ReplyDeleteyou can write or else it is difficult to write.
Also visit my homepage ... healthy diet plans
Because the admin of this web page is working, no doubt very quickly
ReplyDeleteit will be famous, due to its quality contents.
My website; wiki.emsky.net
Wow that was unusual. I just wrοte an rеally lоng comment but аfter Ӏ clickeԁ submit my сomment ԁіdn't show up. Grrrr... well I'm not writіng all
ReplyDeletethat over again. Anywaуs, just ωanted to
sаy gгeat blog!
Also visit my webpage ... stock options training
Hello there! I know this is somewhat off topic but I was wondering if you knew where
ReplyDeleteI could find a captcha plugin for my comment form?
I'm using the same blog platform as yours and I'm having trouble finding one?
Thanks a lot!
My site; this site
Hi colleagues, how is the whole thing, and what you want
ReplyDeleteto say concerning this piece of writing, in my view its
really remarkable designed for me.
Here is my web page; wiki.nviasms.com
Hello! I could have sworn I've been to this website before but after checking through some of the post I realized it's new to me.
ReplyDeleteAnyways, I'm definitely delighted I found it and I'll be bookmarking and checking
back frequently!
Feel free to surf to my webpage: http://www.proyectoslibres.net
Simply wish to say your article is as astounding.
ReplyDeleteThe clarity for your publish is just nice and i can assume you are an expert on this subject.
Well along with your permission allow me to seize your feed to stay up to date with drawing close
post. Thank you a million and please carry on the gratifying work.
my weblog how to save your marriage