EntityFramework-Effort icon indicating copy to clipboard operation
EntityFramework-Effort copied to clipboard

Effort.EF6 not respecting DatabaseGeneratedOption.None

Open RobinhoodBnym opened this issue 6 years ago • 1 comments

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: [email protected]

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

RobinhoodBnym avatar Jun 09 '19 03:06 RobinhoodBnym

Hello @RobinhoodBnym ,

Thank you for reporting, we will look at this.

Best Regards,

Jonathan


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan avatar Jun 09 '19 22:06 JonathanMagnan