asp.net mvc - C# Linq statement to join two tables and multiple columns -


i have 2 tables; endtoend , partport. i'd partporta , partportb data same row in endtoend, , query partport them , corresponding partgid partport on row in partport table. far, i'm able this, have 2 different linq calls i'd reduce down one. here code:

    // demonstrates how join 2 tables, works 1 assetportgid @ time     var part_portgid_a_results = (from icp in entities.endtoend                   icp.intertportgida != null &&                   icp.intertportgidb != null                   join ica in entities.partport                   on icp.partporta   equals ica.portgid                   select new { icp.partporta, ica.partgid, }).tolist();      var part_portgid_b_results = (from icp in entities.endtoend                                    icp.intertportgida != null &&                                    icp.intertportgidb != null                                    join ica in entities.partport                                    on icp.partportb equals ica.portgid                                    select new { icp.partporta, ica.partgid, }).tolist();        return json(part_portgid_a_results, jsonrequestbehavior.allowget); 

what i'd do, , have tried got error this:

                var part_portgid_a_results = (from icp in entities.endtoend                   icp.intertportgida != null &&                   icp.intertportgidb != null                   join ica in entities.partport                   on icp.partporta && icp.partportb   equals ica.portgid                   select new { icp.partporta, ica.partgid, }).tolist(); 

the error is:

guid? endtoend.partportb  error:     operator '&&' cannot applied operands of type 'system.guid' , 'system.guid?' 

you don't have use join. if want join "complex" comparison, make cartesian product (from ... from) , link rows where clause

var part_portgid_results = (from icp in entities.endtoend                             icp.intertportgida != null &&                             icp.intertportgidb != null                             ica in entities.partport                             icp.partporta == ica.portgid                                || icp.partportb == ica.portgid                             select new { icp.partporta, ica.partgid, }).tolist(); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -