Thursday, May 24, 2012

Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)

I got this when i use linq query
query is below
public IQueryable<GasUtilGas> LoadAllForkliftGasUtilByDetailId(int id)
        {
            var res = from gu in db.tblForlkliftGasUtils
                      join g in db.tblGas on gu.GasID equals g.GasID
                      select new GasUtilGas { GasNo = g.GasNumber};
            return res;
        }

It seems like g.GasNumber is a nullable int field in the database.  Change the model to this:
public class GasUtilGas
    {
        public int? GasNo { get; set; }   
    }

No comments:

Post a Comment

How to Create Events Using Microsoft Graph API with Delegated Permissions and MSAL.js

Microsoft Graph API provides powerful capabilities to interact with Microsoft 365 services. In this guide, we’ll explore how to create calen...