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
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 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With