hello, when I try to update my files table in SQL server I am reviving this error message: "Cannot insert explicit value for identity column in table 'Files' when IDENTITY_INSERT is set to OFF."
Any thoughts on what might be causing this? below is a simple class and function of how I am working with ormlite.
public class Files
{
public string F100 { get; set; }
public string F101 { get; set; }
public string FileName { get; set; }
public int FileSize { get; set; }
public int IEventId { get; set; }
[ServiceStack.DataAnnotations.AutoIncrement]
public int? IFileId { get; set; }
public int IFolderId { get; set; }
public Files()
{
}
}
int SomeUpdate( int FileID )
{
using( var dbConn = Helpers.dbFactory().OpenDbConnection())
using( var dbCmd = dbConn.CreateCommand())
using ( var transaction = dbCmd.BeginTransaction())
{
dbCmd.CommandTimeout = Helpers.DatabaseCommandTimeOut;
tFiles.IFolderId = iFolderID;
tFiles.FileName = Microsoft.VisualBasic.Strings.Left(sLongName, 255);
if ( FileID > 0 )
{
tFiles.IFileId = FileID;
dbCmd.Save( tFiles );
tFiles = null;
}
else
{
dbCmd.Insert( tFiles );
FileID = ( int )dbCmd.GetLastInsertId(); //Get Auto Inserted Id;
tFiles = null;
}
transaction.Commit();
}
return FileID;
}