Disabling identity (auto-incrementing) without modifying entity classes (annotations) or datacontext (using fluentapi)

Viewed 65

Is there a way of disabling (Entity Framework 6+, code first) identity increment temporarily for data-migration purposes without changing dbcontext or entities. Is there any Database global property, method etc. or any interceptor injection or any other way to accomplish this.

Let's assume we can not modify the datacontext or entity classes. So I wont be able to use data annotations or fluent API to change identity increment behavior. DataContext and entity classes are in another project and should not be modified since they are being used by a some other apps. And all entities use

[DatabaseGenerated(DatabaseGeneratedOption.Identity)] 

annotation for their ID property.

Is there anyone who has experienced a similar situation or knows how to solve this.

Thanks in advance.

1 Answers

You can add a special-purpose DbContext subtype that overrides the base configuration in OnModelCreating.

Related