PostgreSQL left outer join not working

105 views
Skip to first unread message

Mandor

unread,
Jan 3, 2013, 10:50:17 AM1/3/13
to dbl...@googlegroups.com
Hello is there a known issue for left outer join not working? I think I copied the left join exactly

If I use
         MyDataContext dc = new MyDataContext(conn);
         var q = from stuff in dc.stuffs
                 join price in dc.prices
                 on stuff.sifra equals price.sifra
                 into stuff_price
                 where stuff.name.ToLower().Contains(tbSearch.Text.ToLower())
                    || stuff.shortname.ToLower().Contains(tbSearch.Text.ToLower())
                 from ac in stuff_price.DefaultIfEmpty()
                 select new
                 {
                    stuff.name
                 };

I get all the stuffs from database, but when I add a field from the prices table:

         MyDataContext dc = new MyDataContext(conn);
         var q = from stuff in dc.stuffs
                 join price in dc.prices
                 on stuff.sifra equals price.sifra
                 into stuff_price
                 where stuff.name.ToLower().Contains(tbSearch.Text.ToLower())
                    || stuff.shortname.ToLower().Contains(tbSearch.Text.ToLower())
                 from ac in stuff_price.DefaultIfEmpty()
                 select new
                 {
                    stuff.name
                  ac.price
                 };

I get no stuff out no matter if there is a record in the right table or not.

What am I doing wrong?

Mandor

unread,
Jan 3, 2013, 11:13:00 AM1/3/13
to dbl...@googlegroups.com
Supplement. These are selects that are recorded in PostgreSQL log:

SELECT stuff$."naziv"
FROM "public"."stuffs" stuff$
LEFT JOIN "public"."prices" price$ ON stuff$."sifra" = price$."sifra"
WHERE ((LOWER(stuff$."naziv") LIKE '%' || LOWER(((E''))) || '%') OR (LOWER(stuff$."shortnaziv") LIKE '%' || LOWER(((E''))) || '%'))
SELECT stuff$."naziv", price$."price"
FROM "public"."stuffs" stuff$
LEFT JOIN "public"."prices" price$ ON stuff$."sifra" = price$."sifra"
WHERE ((LOWER(stuff$."naziv") LIKE '%' || LOWER(((E''))) || '%') OR (LOWER(stuff$."shortnaziv") LIKE '%' || LOWER(((E''))) || '%'))

When ran through Squirrel SQL JDBC client they both work as expected.

Mandor

unread,
Jan 4, 2013, 7:56:29 AM1/4/13
to dbl...@googlegroups.com
I changet the order 
         MyDataContext dc = new MyDataContext(conn);
         var q = from stuff in dc.stuffs
                 join price in dc.prices
                 on stuff.sifra equals price.sifra
                 into stuff_price
                 from ac in stuff_price.DefaultIfEmpty()
                 where stuff.name.ToLower().Contains(tbSearch.Text.ToLower())
                    || stuff.shortname.ToLower().Contains(tbSearch.Text.ToLower())
                 select new
                 {
                    stuff.name
                  ac.price
                 };

and changed the type of dc.prices.price form decimal to decimal? (nullable). 
Does this mean i should do this manually every time  i generate datacontext after datamodel change?
Reply all
Reply to author
Forward
0 new messages