Skip to content
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

Existing Guid based ID columns do not work... #82

Open
davidcorbin-atmosera opened this issue Jun 19, 2024 · 2 comments
Open

Existing Guid based ID columns do not work... #82

davidcorbin-atmosera opened this issue Jun 19, 2024 · 2 comments

Comments

@davidcorbin-atmosera
Copy link

Describe the bug
Create a class with a Guid ID that is pre-loaded... it can not be bulk inserted...

To Reproduce
Steps to reproduce the behavior:

  1. Clone BulkInsert.With_Complex_Key
  2. Create class ProductWithExistingGuidKey with an ID field (initialized in Constructor to new Guid)

Expected behavior
Items are bulk inserted.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windo2w 11.
  • N/A
  • Fresh clone of repository a few hours ago.

Additional context
Add any other context about the problem here.

@NorthernLight1
Copy link
Owner

NorthernLight1 commented Jun 19, 2024

@davidcorbin-atmosera,

I am not sure if this is a bug or just a lack of a good error message. You specified an ID column and by default EF will identify it as a primary key column with ValuedGenerated=OnAdd. The extension library is expecting the database to generate the id column. In order to fix this error you would have to specify the "[DatabaseGenerated(DatabaseGeneratedOption.None)]" attribute on the Id column as shown below. I will do some more research on this issue in order to validate my initial findings and I will report what I discover.

public class ProductWithExistingKey { [DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } public ProductWithExistingKey() { Id = Guid.NewGuid(); } }

@davidcorbin-atmosera
Copy link
Author

davidcorbin-atmosera commented Jun 19, 2024

First, thanks for getting back to me so fast....
My expectation (which could be off-base)... is that code that works with DbSet<Entity>.Add(entity) followed by a Context.SaveChanges(). would work without changes when moving to Bulk operations on the same set of entities (into the same Db, etc...)

Yup.... This works,,, but replace back the one line and it fails.... interesting to say the least....

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants