Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type of one of the expressions int he join clause is incorrect. Type inference failed in the call to 'join'

I'm currently trying to join a column from another table to an existing table and return it to the view in MVC 4

var q = from accCo in db.AccControls
        join accCom in db.AccCompanies
        on new { accCo.ControlCode } equals
        new { ControlCode = accCom.Code }

        where accCo.ControlCode == Request.QueryString["ControlCode"]
        orderby accCom.Code
        select new Combined{ AccControls = accCo, AccCompoanies = accCom };

return View(q);

But I'm getting the above error


1 Answers

If any of the columns you join on is nullable, you will need to change it to .Value

on new { accCo.ControlCode } equals
            new { ControlCode = accCom.Code.Value }

or you can use this

var q = from accCo in db.AccControls
    join accCom in db.AccCompanies
    where accCom.Code != null
    on new { accCo.ControlCode } equals
    new { ControlCode = accCom.Code }

    where accCo.ControlCode == Request.QueryString["ControlCode"]
    orderby accCom.Code
    select new Combined{ AccControls = accCo, AccCompoanies = accCom };
like image 141
Vasil Trifonov Avatar answered Dec 15 '25 05:12

Vasil Trifonov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!