Garima Bansal

Garima Bansal

  • 1.1k
  • 680
  • 39.7k

cast to value type 'System.Int32' failed because the materialized

Dec 6 2023 9:47 AM

I am trying to add  increment value in database column and getting error 

cast to value type 'System.Int32' failed because the materialized 

for that i used this way

 if (nameexist.Trim().ToUpper() != model.talukname.Trim().ToUpper())
                        {
                            var MaxValue = (from t in context.ppatalukmasters
                           where t.regioncode == model.regioncode
                            select (int?)t.talukcode).Max() ?? 0;
                          
                            model.talukcode = MaxValue + 1;


but by using this way i cant get increment value

if i use this way

   var MaxValue = (from t in context.ppatalukmasters where t.regioncode == model.regioncode select t.talukcode).Max();
                            model.talukcode = MaxValue + 1;

then i am getting error

 

How i solve this issue?


Answers (1)