0

If I replace product name with a product ID the query works fine. When I choose a Product name that equals "PC" it returns nothing. I know that PC is correct because in SQL it works fine. I use other strings in the Where clause and they all work fine

var query = (from c in Consumer
                    join t in Transactions on c.Con_ID equals t.Con_ID
                    join s in Supplier on t.Supp_ID equals s.Supp_ID
                    join p in Product on t.Prod_ID equals p.Prod_ID
                     where p.Name == "PC" && c.City == "Wausau" && s.City == "Madison"
                        select new { SupplierName = s.Name }).Distinct();

I'm using Entity Reference Model here. Is it possible that there is an incorrect mapping for the Name field on Product or have I missed something obvious?

JasonTheLucky
  • 177
  • 11
  • 1
    Are you sure it is failing on "PC", and not "Wausau" or "Madison"? Have you tried it with just `where p.Name == "PC"`? – Bob. Apr 19 '13 at 18:57
  • 1
    can you show us the record for `Name="PC"`? – Arian Apr 19 '13 at 20:16
  • select * from Tb_Product where name = 'PC' Prod_ID Name MU 1 PC Pieces – JasonTheLucky Apr 19 '13 at 21:02
  • Also, if I remember correctly, EntityFramework sometimes messes up with `==` on strings. Try doing `p.Name.Equals("PC", StringComparison.OrdinalIgnoreCase)` and the like (see the top answer here: http://stackoverflow.com/questions/8105732/ef-4-1-linq-to-sql-what-is-better-using-equals-or) – valverij Apr 19 '13 at 21:02

0 Answers0