sql - Empty result set when Joining two table with Non-match Foreign key -


i joining 2 tables using foreign key. table_1 might have row null foreign key. means when join 2 tables based on foreign key won't results it. problem when use join 2 tables in linq, empty result set.

i want able row in table_1 if join result no match table_2.

i tried use defaultifempty in join of table_2, still empty result set. how can join 2 tables , still result if table_1 contains null in foreign key use join 2 table?

thanks

hi try left join table2 table1

class program {     static void main(string[] args)     {         list<table1> table_1 = new list<table1>();         table_1.add(new table1() { id = 1, name = "lion" });         table_1.add(new table1() { id = 2, name = "elephant" });           list<table2> table_2 = new list<table2>();         table_2.add(new table2() { id = 1, class = "carnivorous" });         table_2.add(new table2() { id = 2, class = "herbivorous" });         table_2.add(new table2() { id = 3, class = "mammal" });         table_2.add(new table2() { id = 4, class = "aquarious" });           var result = (from in table_2                       join b in table_1                       on a.id equals b.id leftjoin                       c in leftjoin.defaultifempty()                       select new { id = a.id, name = c == null ? string.empty : c.name, class = a.class }                    ).tolist();          var abc = result;     } }  public class table1 {     public int id;     public string name; }  public class table2 {     public int id;     public string class; } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -