Type Inference failed in a call to 'join' on nullable and non-nullable int

后端 未结 6 1932
半阙折子戏
半阙折子戏 2021-01-12 02:20

In my Linq, I am trying to make an inner join to a nullable field. Employee and Department have a relation, Department may have an EmployeeID or may have a null. So what wou

6条回答
  •  青春惊慌失措
    2021-01-12 03:06

    I had the same issue, where my charge_codes.CompanyId was nullable but my order_items.CompanyId was NOT nullable.

    So I had to get my charge codes into their own ananomous type and make it not be nullable.

    var chargeCodes = from s in db.Charge_Codes
    where s.CompanyID != null
    select new { CompanyID = (int)s.CompanyID, 
                 Charge_CodeID = s.Charge_CodeID, 
                 Revenue_Code_Id = (int)s.Revenue_CodeID, };
    
    
    
    //now my chargeCodes contains an anonymous with a non nullable CompanyID and 
    //a non nullable Revenue_CodeID 
    
    //use chargeCodes here
    var query = from oi in db.Order_Items
    join cc in chargeCodes on 
    new {oi.CompanyID, oi.Charge_CodeID} equals new {cc.CompanyID, cc.Charge_CodeID}
    

提交回复
热议问题