-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
nvarchar(max) for identity columns creates issues with indexes #4226
Comments
update: I hacked the column directly following instructions from (http://stackoverflow.com/questions/26950625/how-to-create-an-index-for-a-string-property-in-entity-framework-7). But that led to an issue where EF can't load a user - even a base applicationuser - out of the database when they are logged in or I try to enumerate them. It was able to create the user, but just can't get it back out. The application is working fine for access to all other objects. Is it possible to tell from the stack trace which property it is hacking on? Microsoft.Data.Entity.Query.Internal.SqlServerQueryCompilationContextFactory: Error: An exception occurred in the database while iterating the results of a query. |
@esargent there are two issues you are hitting here.
Until #2455 is fixed, you will need to manually edit the scaffolded migration to specify an explicit type to use. migrationBuilder.AddColumn<string>(
name: "PrimaryDistributorId",
table: "AspNetUsers",
nullable: true,
type: "nvarchar(450)"); I'm closing this out, since the fundamental issues are already tracked by other issues. |
I thought this might be fixed in rc2 when Issue 1071 was closed but it seems to still be an issue. Could also be related to Issue 4134. I experienced this in rc1-final and now in 7.0.0-rc2-16649
Use Case:
I've inherited several classes from ApplicationUser - such as Distributor and Customer. I want my Customer to have a primary distributor
What happens
The code compiles and I can generate a migration, but the migration script, which I can capture with the -o option, shows that Customer.PrimaryDistributorId is being created as nvarchar(max) which doesn't match ApplicationUser.Id which is nvarchar(450) so create index fails. (They are all being created in the AspNetUsers table, which is what I expected.)
I think I can fix that so add to my OnModelCreating()
which is what was suggested as a workaround in the discussion for 1071, but it still generates nvarchar(max) as the type, which causes an error when the script tries to create the index.
Not really clear if I am stuck here or if there is another workaround? Or am I doing something wrong?
The text was updated successfully, but these errors were encountered: