G
Geol4549
Guest
ASP.Net Core MVC project using Visual Studio 2019 and EntityFrameworkCore
The domain model consists of a header type (PullHdr) with a primary key PullHdrId (int) and a related item type (PullItem) with primary key PullItemId (int). PullHdr type has a collection property PullItems (virtual ICollection<PullItem>). My hope/expectation is that the integer object Id fields will update incrementally. That is not happening. So records are not being added to the SQL database. I added seed data to the database so I know it is functional.
When I execute the context.SaveChanges() method I receive:
SqlException: Cannot insert explicit value for identity column in table 'PullItems' when IDENTITY_INSERT is set to OFF.
I don't really want to set the Identity_Insert option if I don't have to. I tried to set the PullHdrId and PullItemId properties to null by explicitly implementing private backing fields pullHdrId and pullItemId (as int?) with default values set to null . I received the same error message. Is it a matter of rerunning the migration or something else I've overlooked?
Thanks
Continue reading...
The domain model consists of a header type (PullHdr) with a primary key PullHdrId (int) and a related item type (PullItem) with primary key PullItemId (int). PullHdr type has a collection property PullItems (virtual ICollection<PullItem>). My hope/expectation is that the integer object Id fields will update incrementally. That is not happening. So records are not being added to the SQL database. I added seed data to the database so I know it is functional.
When I execute the context.SaveChanges() method I receive:
SqlException: Cannot insert explicit value for identity column in table 'PullItems' when IDENTITY_INSERT is set to OFF.
I don't really want to set the Identity_Insert option if I don't have to. I tried to set the PullHdrId and PullItemId properties to null by explicitly implementing private backing fields pullHdrId and pullItemId (as int?) with default values set to null . I received the same error message. Is it a matter of rerunning the migration or something else I've overlooked?
Thanks
Continue reading...