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

Insert Order #467

Closed
rubenalves opened this issue Jul 29, 2014 · 1 comment
Closed

Insert Order #467

rubenalves opened this issue Jul 29, 2014 · 1 comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Milestone

Comments

@rubenalves
Copy link

I have noticed that when i add several items to a DbSet, example,

db.Products.Add(new Product{ID = 1, Name = "Product 1"});
db.Products.Add(new Product{ID = 2, Name = "Product 2"});
db.Products.Add(new Product{ID = 3, Name = "Product 3"});

When db.SaveChages() is called the data is inserted in the database but the order is random, not the order that the products where inserted in the collection.

Is it possible to make the ID column not identity and specify the ID manually as in my example?

@rowanmiller rowanmiller added this to the Discussions milestone Aug 1, 2014
@rowanmiller
Copy link
Contributor

Hey Ruben,

Yes you can override the 'integer primary keys are identity' convention by configuring the entity:

modelBuilder.Entity<Product>()
    .Property(p => p.ID)
    .GenerateValuesOnAdd(false);

You'll also be able to use the [DatabaseGenerated] attribute once Data Annotation support is enabled in EF7.

We do also have #703 tracking the ability to explicitly insert values into a column that is configured as identity (for a set of well-known seed data etc.).

@AndriySvyryd AndriySvyryd added the closed-no-further-action The issue is closed and no further action is planned. label Oct 9, 2017
natemcmaster pushed a commit that referenced this issue Oct 31, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

4 participants