A join Extension Method for the dynamic LINQ

Source: Internet
Author: User

Http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/4482b083-72bd-4415-82be-8cccbd9eabba

 

 

Public   Static Iqueryable join ( This Iqueryable outer, ienumerable inner, String Outerselector, String Innerselector, String Resultsselector, Params   Object [] Values)
{
If (Inner =   Null ) Throw   New Argumentnullexception ( " Inner " );
If (Outerselector =   Null ) Throw   New Argumentnullexception ( " Outerselector " );
If (Innerselector =   Null ) Throw   New Argumentnullexception ( " Innerselector " );
If (Resultsselector =   Null ) Throw   New Argumentnullexception ( " Resultsselctor " );

Lambdaexpression outerselectorlambda=Dynamicexpression. parselamtype (outer. elementtype,Null, Outerselector, values );
Lambdaexpression innerselectorlambda=Dynamicexpression. parselamner (inner. asqueryable (). elementtype,Null, Innerselector, values );

Parameterexpression [] Parameters =   New Parameterexpression [] {
Expression. parameter (outer. elementtype, " Outer " ), Expression. parameter (inner. asqueryable (). elementtype, " Inner " )};
Lambdaexpression resultsselectorlambda = Dynamicexpression. parselamters (parameters, Null , Resultsselector, values );

Return Outer. provider. createquery (
Expression. Call (
Typeof (Queryable ), " Join " ,
New Type [] {outer. elementtype, inner. asqueryable (). elementtype, outerselectorlambda. Body. type, resultsselectorlambda. Body. Type },
Outer. expression, inner. asqueryable (). Expression, expression. Quote (outerselectorlambda), expression. Quote (innerselectorlambda), expression. Quote (resultsselectorlambda )));
}

// The generic overload.
Public   Static Iqueryable < T > Join < T > ( This Iqueryable < T > Outer, ienumerable < T > Inner, String Outerselector, String Innerselector, String Resultsselector, Params   Object [] Values)
{
Return (Iqueryable < T > ) Join (iqueryable) Outer, (ienumerable) Inner, outerselector, innerselector, resultsselector, values );
}

 

Application

 


VaR aaa = Context. dict. Where (P => P. dictionaryid > 3 ). Select (P => P. dictionaryid );

VaR bbb=Context. dict. Join (AAA,"Dictionaryid","It","Outer"); 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.