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?