Search code examples
c#oracleentity-frameworkasp.net-identityowin

UserManager.FindByName() throwing EntityCommandExecutionException. Why is it using "EXTENT1"."USERNAME1"?


I'm using Oracle DB, Entity Framework, Microsoft ASP.NET Identity, OWIN, and OWIN-MixedAuth.

Inside the execution of UserManager.FindByName(name), I'm getting: "EntityCommandExecutionException: An error occurred while executing the command definition." The internal exception is OracleException: ORA-00904: "Extent1"."USERNAME1": invalid identifier."

It is entirely true that I don't have a column named "USERNAME1" in the database, and it makes sense that the Identity framework can't find that column. The trouble is: I don't know why it's looking for that column to begin with. The IdentityUser.UserName is mapped explicitly in the DbContext like so:

modelBuilder.Entity<MyUser>().Property(r => r.UserName).HasColumnName("USERNAME");

I searched my code for "USERNAME1" just in case I had an ill-defined magic string somewhere, but there are no results found in my code. I've searched for this error, but it seems like I'm the only one getting this kind of error from inside the framework.

Can anyone think of anyplace where its getting this column name and how I can correct it?

Thanks in advance.


Solution

  • These "phantom" columns happen when you tell EF that column A on one entity is a primary/foreign key of a column B on another entity. If the relationship is misconfigured, what happens is one of the columns is duplicated with a number added, and that column is used as a key, not your original intended column. It's a matter of how your entities are set up.