none
How to use Join on about not equals in LINQ Dataset?

    Question

  • How to use Join on about not equals in LINQ Dataset? As follows:

    select a.id,a.v1,a.num,a.m1,a.m2,a.m3 from
    (select t1.id,t1.v1,t2.num,t2.m1,t2.m2,t2.m3 from t1 inner join t2 on t1.id=t2.id
    union all
    select t1.id,t1.v1,t2.num,null as m1,null as m2,null as m3 from t1 inner join  t2 on t1.id<>t2.id
     ) a
    order by a.num,a.id

    How to convert the sql  to the LINQ Dataset ?


    天崖------Flacker Tchang

    Tuesday, July 16, 2013 9:43 AM

Answers

  • var query=(from t1 in db.t1

                     from t2 in db.t2

                     where t1.id=t2.id

                     select new(id=t1.id,v1=t1.v1, num=t2.num,m1=t2.m1,m2=t2.m2,m3=t2.m3). union

                     (from t1 in db.t1

                     from t2 in db.t2

                     where t1.id!=t2.id

                     select new(id=t1.id,v1=t1.v1, num=t2.num,m1=t2!=null?t2.m1:null,m2=t2!=null?t2.m2:null,m3=t2!=null?t2.m3:null);

                     

                     

                     

                     

      


    天崖------Flacker Tchang

    • Marked as answer by HeavenCliff Wednesday, July 17, 2013 3:06 AM
    Wednesday, July 17, 2013 3:05 AM

All replies

  • Hi Flacker,

    You might want to post this question to a 'Data Platform Development forums'. I am moving this thread to Data Platform Development forums > LINQ to SQL

    Thanks,

    Gaurav

    Tuesday, July 16, 2013 4:20 PM
  • Thanks

    天崖------Flacker Tchang

    Wednesday, July 17, 2013 12:49 AM
  • var query=(from t1 in db.t1

                     from t2 in db.t2

                     where t1.id=t2.id

                     select new(id=t1.id,v1=t1.v1, num=t2.num,m1=t2.m1,m2=t2.m2,m3=t2.m3). union

                     (from t1 in db.t1

                     from t2 in db.t2

                     where t1.id!=t2.id

                     select new(id=t1.id,v1=t1.v1, num=t2.num,m1=t2!=null?t2.m1:null,m2=t2!=null?t2.m2:null,m3=t2!=null?t2.m3:null);

                     

                     

                     

                     

      


    天崖------Flacker Tchang

    • Marked as answer by HeavenCliff Wednesday, July 17, 2013 3:06 AM
    Wednesday, July 17, 2013 3:05 AM