-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explict Value can't be inserted in Table when IDENTITY_INSERT is OFF #6006
Comments
Any chance you could provide a console app style code listing that we could run to see the issue? Without the complete code listing for your model and the context around what is stored in |
This is happening for me also public partial class Intake
{
public int IntakeID { get; set; }
public DateTimeOffset? AccidentDtm { get; set; }
public int AddedByUserID { get; set; }
public DateTimeOffset AddedDtm { get; set; }
public int? ApprovedByUserID { get; set; }
public DateTimeOffset? ApprovedDtm { get; set; }
public int? AssignedToUserID { get; set; }
public DateTimeOffset? CallbackAttempt1Dtm { get; set; }
public DateTimeOffset? CallbackAttempt2Dtm { get; set; }
public DateTimeOffset? CallbackAttempt3Dtm { get; set; }
public int CaseTypeCategoryID { get; set; }
public bool Deleted { get; set; }
public int? DispositionCategoryID { get; set; }
public DateTimeOffset DispositionDtm { get; set; }
public string HospitalDoctor { get; set; }
public string HowOccur { get; set; }
public string Injury { get; set; }
public int LastUpdatedByUserID { get; set; }
public DateTimeOffset LastUpdatedDtm { get; set; }
public string Notes { get; set; }
public int PrimaryContactID { get; set; }
public DateTimeOffset ReceivedDtm { get; set; }
public int ReferredByCategoryID { get; set; }
public string ReferredByOther { get; set; }
public int TakenByCategoryID { get; set; }
public DateTime? WorkCompReportedDt { get; set; }
public string WorkCompReportedTo { get; set; }
public virtual VcaseUser AddedByUser { get; set; }
public virtual VcaseUser ApprovedByUser { get; set; }
public virtual VcaseUser AssignedToUser { get; set; }
public virtual Category CaseTypeCategory { get; set; }
public virtual Category DispositionCategory { get; set; }
public virtual VcaseUser LastUpdatedByUser { get; set; }
public virtual Contact PrimaryContact { get; set; }
public virtual Category ReferredByCategory { get; set; }
public virtual Category TakenByCategory { get; set; }
}
public class AppDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Intake>(entity =>
{
entity.Property(e => e.IntakeID).ValueGeneratedOnAdd().UseSqlServerIdentityColumn();
entity.Property(e => e.Deleted).HasDefaultValue(false);
entity.Property(e => e.ReferredByOther).HasMaxLength(100);
entity.Property(e => e.WorkCompReportedDt).HasColumnType("date");
entity.Property(e => e.WorkCompReportedTo).HasMaxLength(100);
entity.HasOne(d => d.AddedByUser).WithMany(p => p.Intake).HasForeignKey(d => d.AddedByUserID).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(d => d.ApprovedByUser).WithMany(p => p.IntakeNavigation).HasForeignKey(d => d.ApprovedByUserID);
entity.HasOne(d => d.AssignedToUser).WithMany(p => p.Intake1).HasForeignKey(d => d.AssignedToUserID);
entity.HasOne(d => d.CaseTypeCategory).WithMany(p => p.Intake).HasForeignKey(d => d.CaseTypeCategoryID).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(d => d.DispositionCategory).WithMany(p => p.IntakeNavigation).HasForeignKey(d => d.DispositionCategoryID).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(d => d.LastUpdatedByUser).WithMany(p => p.Intake2).HasForeignKey(d => d.LastUpdatedByUserID).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(d => d.PrimaryContact).WithMany(p => p.Intake).HasForeignKey(d => d.PrimaryContactID).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(d => d.ReferredByCategory).WithMany(p => p.Intake1).HasForeignKey(d => d.ReferredByCategoryID).OnDelete(DeleteBehavior.Restrict);
entity.HasOne(d => d.TakenByCategory).WithMany(p => p.Intake2).HasForeignKey(d => d.TakenByCategoryID).OnDelete(DeleteBehavior.Restrict);
});
}
} |
@Benny739 @brandonseydel You may be hitting this: #703. If your issue is not this, then we will need code showing how the context is being used in order to investigate this. |
Its when I add an entity and attach it it behaves this way. this._context.Intakes.Add(intake); //Works
_context.Intakes.Attach(intake).State = EntityState.Added; //Fails |
EF Team Triage: This issue is lacking enough information for us to be able to effectively triage it. In particular, it is missing the following information requested in the new issue template. Can you please provide this information?
BTW we're not just doing this to be mean 😄... we get a lot traffic on this project and it takes time to attempt to reproduce an issue based on fragments of information. In addition, our attempt is often unsuccessful as the exact conditions required to hit the issue are often not explicitly included in the code provided. To ensure we maximize the time we have to work on fixing bug, implementing new features, etc. we ask that folks give us a self contained way to reproduce an issue. For a guide on submitting good bug reports, read_ Painless Bug Tracking. |
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it. |
I get an error when I try to insert a value in my Table.
_dltype
is an object of typeBRIDownloadType
. I pass it from another class.Now I get the error:
My 2 Tables are
BRIDownloadType
BRITodo
The interesting thing is, if I do something with my
_dltype
object, I can use it.The following code is working but I'm still inserting the same object.
I just added the line and the code is working.
I'm using Version 1.0.0 with SqlServer in a Windows Forms Project.
The text was updated successfully, but these errors were encountered: