Here is the two important bits. I have a taxpayerID that comes from the Current users profile, but then I want to move that value from the ASPNETDB database into my actual transaction database, so I know the value, but this code fails. It will insert the first time and fail on every following save,
{"A duplicate value cannot be inserted into a unique index. [ Table name = dr405,Constraint name = PK_dr405_0000000000000072 ]"}
I've tried deleting the database to clear out any cobwebs and that did not seem to help.
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public String TaxPayerID { get; set; }
public DateTime CreateDate { get; set; }
public void Save(DR405DBContext context, dr405 obj)
{
if (obj.CreateDate == null)
{
obj.CreateDate = DateTime.Now;
}
obj.ModDate = DateTime.Now;
context.Entry(obj).State = obj.TaxPayerID == null ? EntityState.Added : EntityState.Modified;
obj.TaxPayerID = Tangible.Profiles.DR405Profile.CurrentUser.TaxPayerID;
context.SaveChanges();
}