Sachin R

Sachin R

  • NA
  • 91
  • 7.1k

Code first migration data type issue with C# and SQLserver

May 28 2015 10:51 AM
For simple membership in my register model I have add a column/property with datatype as below(highlighted) but its giving me arithmetic overflow exception while inserting data to table..  Please help me on this on what went wrong here
 
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[Required]
[Display(Name = "Email Id")]
public string EmailId { get; set; }

[Required]
public Int64 Mobile { get; set; }
 
 Userprofile table model
 
 
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
//Added by me
public string EmailId { get; set; }
public Int64 Mobile { get; set; }
}
 
 Error
 
 
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Arithmetic overflow error converting expression to data type int.
The statement has been terminated.
Source Error:
Line 80: try
Line 81: {
Line 82: WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new {model.EmailId,model.Mobile });
Line 83: WebSecurity.Login(model.UserName, model.Password);
Line 84: return RedirectToAction("Index", "Home");
 
Table definition from SQLSERVER
 
CREATE TABLE [dbo].[UserProfile](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[UserName] [nvarchar](56) NOT NULL,
[EmailId] [nvarchar](max) NULL,
[Mobile] [int] NOT NULL,
 

Answers (2)