Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Thursday, 27 July 2017

Difference Between Select And Where In LINQ

 asp.net, C#, LINQ     No comments   

Introduction
In this article we will learn what is LINQ. What is the difference between Select and where in linq. Example of Linq Where and Select.

Previous Updates
In previous articles we have learnt  Why every business needed digital Marketing  ,What is Lock and how to achieve lock on sql table. Authorization in Asp.Net. How high quality content affects your Website. What is Blocking and Deadlock In SQL. Transaction Commit and Rollback in sql server with example.

Select and Where are two completely different operators acting on IEnumerables

Select : (IEnumerable<T1>, Func<T1,T2>) -

Select in Linq takes Ienumerable type of input T1 and Func (function) produce a boolean result for an in
In other words Select is a projection, so what you get is the expression x=> x.Name== "JP" evaluated for each element in MyList() on the server. i.e. lots of true/false values (the same number as your original list). If you look the select will return something like IEnumerable<bool> (because the type of x=> x.Name == "John" is a bool).

var a = MyList.SELECT(x => x.Id == id).SingleOrDefault();

public static IEnumerable<TResult> Select<TSource , TResult>
                   ( this IEnumerable<TSource> a , Func<TSource , TResult> Method )
{
    foreach ( var item in a )
    {
        //Each iteration call the delegate and return the Data back.
           // (use 'yield' for deferred return)
        yield return Method.Invoke ( item );
    }
}

Related topics - Difference between Ienumerable and Iqueryable. LINQ overview , Advantanges and Lamda expression in LINQ.

Where : (IEnumerable<T1>, Func<T1, bool>) 

Where in Linq takes Ienumerable type of input T1 and Func (function) transferring element of Type T1 into element of Type T2.

var a = MyList.Where(x => x.Id == id).SingleOrDefault();
public static IEnumerable<Tsource> Where<Tsource> 
               ( this IEnumerable<Tsource> a , Func<Tsource , bool> Method )
{
    foreach ( var data in a )
    {
        //If the lambda Expression(delegate) returns "true" Then return the Data. 
       //(use 'yield' for deferred return)
        if ( Method.Invoke ( data ) )
        {
            yield return data;
        }
    }
}
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home
View mobile version

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write