Dear All,
I have a table called Operator. It has a primary key called OperatorID.
This primary key was an int before. but because I have to create an offline extension of software platform. so I changed the OperatorID to string.
So right now my primary key is a string data type. But anytime I want to insert values into the table I get this strange error message. Even when I create a string as primary key. I have been on this for 2 days. Honestly I dont know what to do.
Server Error in '/' Application.
Cannot insert the value NULL into column 'OperatorID', table 'aspnet-LiveChatPrototype.Mvc-06994222340982220000004.dbo.Operator'; column does not allow nulls. INSERT fails.
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: Cannot insert the value NULL into column 'OperatorID', table 'aspnet-LiveChatPrototype.Mvc-06994222340982220000004.dbo.Operator'; column does not allow nulls. INSERT fails.
Source Error:
Line 169: {
Line 170: this.context.Operators.Add(chatoperator);
Line 171: await this.context.SaveChangesAsync();
Line 172:
Line 173: operatorID = chatoperator.OperatorID;
Source File: C:\Users\skliz\Documents\Visual Studio 2019\sources\repos\Promptfinder\LiveChatPrototype.DAL\Repository\Provideradmin\OperatorRepository.cs Line: 171 My POCO class
public class Operator
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string OperatorID { get; set; }
//This is a foriegn key. links to the moderator table
// public int ModeratorID { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
public string Loginpinhash { get; set; } //This is a 4 digit login pin that helps admin secure activities on the mobile app
...............................My Business logic that talks to the DAL repository for this particular table.
public async Task<string> CreateOperator_returnID(CreateOperatorView model, int CompanyID)
{
string operatorID = "";
DayDetails daytiming = new DayDetails();
DateTime currentdate = daytiming.CurrentDate();
TimeSpan currenttime = daytiming.CurrentTime();
string passwordSalt = CryptoHelper.CreateSalt();
string hashpassword = (model.Password.ToSha512(passwordSalt));
string hashconfirmpass = (model.Confirm_Password.ToSha512(passwordSalt));
operatorID = Stringgenerator.Generatenewpassword();
Operator operatorEntity = new Operator()
{
OperatorID = operatorID,
Activated = true,
//Address = model.Address,
DateCreated = currentdate,