Skip to content

Effort.EF6 not respecting DatabaseGeneratedOption.None #171

@RobinhoodBnym

Description

@RobinhoodBnym

Description

I have a Entity class with the Key column attribute. As per entity framework default behavior for the key column is DatabaseGenerated = DatabaseGeneratedOption.None.
But Effort.EF6 is auto incrementing the column value and ignoring the value assigned by me.

Exception

It should not generate the value for Key column and should respect the assigned value.

Exception message:
Foreign key violation [dbo_DependantEntities :: MainEntityId]. The key value [101] does not exists in the referenced table [dbo_MainEntities :: MainEntityId].. Error code: RelationError

```text
Stack trace:
System.Data.Entity.Infrastructure.DbUpdateException
  HResult=0x80131501
  Message=An error occurred while updating the entries. See the inner exception for details.
  Source=EntityFramework
  StackTrace:
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at ConsoleApp1.InMemoryDbInitializer.SeedAllData(MyDbContext context) in C:\Users\BNYMELLON\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 51
   at ConsoleApp1.InMemoryDbInitializer.Init(MyDbContext context) in C:\Users\BNYMELLON\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 25
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\BNYMELLON\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 16

Inner Exception 1:
UpdateException: An error occurred while updating the entries. See the inner exception for details.

Inner Exception 2:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 3:
ForeignKeyViolationException: Foreign key violation [dbo_DependantEntities :: MainEntityId]. The key value [101] does not exists in the referenced table [dbo_MainEntities :: MainEntityId].. Error code: RelationError

Project

Provide a project/solution that we can run to reproduce the issue.

  • Make sure the project compile
  • Make sure to provide only the code that is required to reproduce the issue, not the whole project
  • You can send private code here: info@zzzprojects.com

Note: If you are not able to provide code we can run and that reproduce the issue, we will not be able to fix it either.

Further technical details

  • EF version:6.0
  • EF Effort version: 2.1.0
  • Database Provider:SqlServer
    ConsoleApp1.zip

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions