zzzprojects / EntityFramework-Effort

Entity Framework Effort is a powerful tool that enables a convenient way to create automated tests for Entity Framework based applications.
https://entityframework-effort.net/
MIT License
431 stars 99 forks source link

Effort.EF6 not respecting DatabaseGeneratedOption.None #171

Open RobinhoodBnym opened 5 years ago

RobinhoodBnym commented 5 years ago

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.

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

JonathanMagnan commented 5 years ago

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