السؤال Dynamic LINQ

  • Thursday, January 03, 2013 3:27 PM
     
     

    hi all,

    i want to write a dynamic linq like this in C#

    but, my doubt is, how do i write left outer join like above example(using dynamic LINQ).?

    experts pleasse guide me.


    Thanks In Advance, Jeyaseelan


    • Edited by jeyaseelan2 Thursday, January 03, 2013 4:03 PM
    •  

All Replies

  • Thursday, January 03, 2013 4:03 PM
     
     
    experts please guide me.

    Thanks In Advance, Jeyaseelan

  • Thursday, January 03, 2013 4:54 PM
     
     

    Hi jeyaseelan2,

    left outer join in LINQ is done with the help of DefaultIfEmpty() method. It will be better if you use sql version of LINQ insteed of methodised version as you have done, something like this :

    Dim query = From el in Products _
                Join t in xyz on el equals t.SomeField into gj_
                From t1 in gj.DefaultIfEmpty()
                Where el.CategoryID=2 And UnitPrice>3 _
                Select New ....
               

    Please folow this link where left outer join in LINQ has been explained.Though it is in C# it will not matter to convert to VB.NET.


    One good question is equivalent to ten best answers.

  • Friday, January 04, 2013 2:59 AM
    Moderator
     
     

    Hi Jeyaseelan,

    You can use Enumerable.GroupJoin method: http://msdn.microsoft.com/en-us/library/vstudio/bb534297.aspx

    There is a simple example on previous link.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Friday, January 04, 2013 11:42 AM
     
     
    thanks for your reply but, my situation is i dont know what are all the columns will come for where clause so, as per the example i cant hardcode the column names.

    Thanks In Advance, Jeyaseelan

  • Friday, January 04, 2013 11:44 AM
     
     

    I also wanted left join solution with DLINQ but couldn't find it. However I can suggest you general LINQ  LEFT JOIN solution from my blog post.

    http://msguy.net/post/2013/01/04/LINQ-Join-Operations.aspx#left-join


    Please Mark as Reply and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.net/

  • Friday, January 04, 2013 12:27 PM
     
     
    thanks for your interest michel but, i want it in DLINQ

    Thanks In Advance, Jeyaseelan

  • Tuesday, January 08, 2013 8:49 AM
    Moderator
     
     

    Hi Jeyaseelan,

    I don’t understand. Do you mean you don’t know column names and don’t know how to use column names in groupjoin?

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Saturday, January 12, 2013 2:04 PM
     
     
    thanks for your reply but, my situation is i dont know what are all the columns will come for where clause so, as per the example i cant hardcode the column names.

    Thanks In Advance, Jeyaseelan

    In your first posted example, you know what the columns are. They are all column from table products that match the criteria in the where clause. So, You don't need to hardcode the columns..

    btw.. you begin with an example that has no relation with your questions.. What do you want exactly?


    Blog: http://samir-ibrahim.blogspot.com/