Question on RowVersion TImestamp
Posted: Sat 14 Apr 2018 09:52
HI
I facing a problem it is related to Timestamp.
If i using following code
then i will get an error likes this.
"The 'RowVersion' property on 'OMTran' could not be set to a 'System.DateTime' value. You must set this property to a non-null value of type 'System.Byte[]'. "
but if i using below code then no problem.
my omtran class
is my class problem? or it is standard?
and how to use isTimestamp() method?
I facing a problem it is related to Timestamp.
If i using following code
Code: Select all
using (ApplicationDbContext db = new ApplicationDbContext())
{
db.Configuration.LazyLoadingEnabled = false;
db.Configuration.AutoDetectChangesEnabled = false;
int Oid = dbObj.Id;
var dbObjUpd = db.OMTrans.Where(u => u.Id == Oid).FirstOrDefault();
dbObjUpd.Oid = int.Parse(returnedString);
dbObjUpd.Mupd_DateTime = DateTime.Now;
db.Entry(dbObjUpd).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
}
"The 'RowVersion' property on 'OMTran' could not be set to a 'System.DateTime' value. You must set this property to a non-null value of type 'System.Byte[]'. "
but if i using below code then no problem.
Code: Select all
using (ApplicationDbContext db = new ApplicationDbContext())
{
db.Configuration.LazyLoadingEnabled = false;
db.Configuration.AutoDetectChangesEnabled = false;
List<int> ListObjInt = new List<int>();
ListObjInt.Add(dbObj.Id);
var dbObjUpd = db.OMTrans.Where(u => ListObjInt.Contains(u.Id)).FirstOrDefault();
dbObjUpd.Oid = int.Parse(returnedString);
dbObjUpd.Mupd_DateTime = DateTime.Now;
db.Entry(dbObjUpd).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
}
Code: Select all
[Table("OMTran")]
public partial class OMTran
{
public OMTran()
{
}
[Key]
[Column("Id", TypeName = "int")]
public int Id { get; set; }
[Display(Name = "Oid")]
[Column("Oid", TypeName = "int")]
public int? Oid { get; set; }
[Required]
[Column("CompanyId", TypeName = "int")]
public int CompanyId { get; set; }
[Required]
[Column("StoreId", TypeName = "int")]
public int StoreId { get; set; }
[Required]
[Column("OMDocId", TypeName = "int")]
public int OMDocId { get; set; }
[ForeignKey("OMDocId")]
public virtual OMDoc OMDoc { get; set; }
[Column("Lupd_DateTime", TypeName = "datetime")]
public DateTime Lupd_DateTime { get; set; }
[Column("Lupd_UserId", TypeName = "varchar")]
[StringLength(255)]
public string Lupd_UserId { get; set; }
[Column("Lupd_Prog", TypeName = "varchar")]
[StringLength(50)]
public string Lupd_Prog { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
public ICollection<OMLot> OMLots { get; set; }
}
and how to use isTimestamp() method?