locked
Unable to cast object of type 'System.String' to type 'System.Int32'. Please help urgent RRS feed

  • Question

  • User-1355965324 posted

    I deleted from the sqlserver table an unnecessary constraint from the user table. After that  the error being always showed  Unable to cast object of type 'System.String' to type 'System.Int32'. in general Repo. Please help urgent in the line . How can I fix Please help

     public T Get(int id)
            {
                return dbSet.Find(id);
            }

    Monday, August 24, 2020 2:31 PM

Answers

  • User-1355965324 posted

    I got the reason for that because the  value of the record in a table is null bu it was defined as 'required' in the   model. So I fixed. 

    Thanks mgebhard

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 25, 2020 8:58 AM

All replies

  • User475983607 posted

    I deleted from the sqlserver table an unnecessary constraint from the user table. After that  the error being always showed  Unable to cast object of type 'System.String' to type 'System.Int32'. in general Repo. Please help urgent in the line . How can I fix Please help

     public T Get(int id)
            {
                return dbSet.Find(id);
            }

    The error is very clear.  The code tries to assign or pass a string to an input or variable that expects an integer. 

    Polachan, it's very helpful if you explained what "unnecessary" constraint was deleted from the user table.  You must have had a reason to delete the "unnecessary" constraint.  Is there anyway you can explain what you are trying to do?  Did you change a primary key type from a string to an int?

    Monday, August 24, 2020 3:20 PM
  • User-1355965324 posted

    I got the reason for that because the  value of the record in a table is null bu it was defined as 'required' in the   model. So I fixed. 

    Thanks mgebhard

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 25, 2020 8:58 AM