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

TinyMCE Insert/Edit link not editable

 To fix this add  e.stopImmediatePropagation()  as below. $(document).on('focusin', function (e) {             if ($(e.target).close...