1
UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>());
OAuthOptions = new OAuthAuthorizationServerOptions
{
    TokenEndpointPath = new PathString("/Token"),
    Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
    AuthorizeEndpointPath = new PathString("/api/AccountOwin/ExternalLogin"),
    AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
    AllowInsecureHttp = true
};

From which IdentityUser,UserStore comesform entity framework.

I want to use my database instead of local db, I generated the "generate" script from the local db tables and I created them in my custom database but when I chanhe the db context in the below row:

UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>(new MyCustomDBEntities()));

Where MyCustomDBEntities is my custom database in entity framework (edmx) I'm getting the following error: "The entity type IdentityUser is not part of the model for the current context"

What I am doing wrong? Should I create my own Usermanager?

public class MyCustomDBEntities : IdentityDbContext<IdentityUser>
    {
        public MyCustomDBEntities()
            : base("name=ConnectionStringName")
        {
        }
    }
Lóri Nóda
  • 694
  • 1
  • 10
  • 20
  • Are you sure you generated the tables correctly in the new database? – DavidG May 28 '14 at 14:44
  • Yes because I used management studio for generating the create scripts. The interesting thing is that the system doesn't generated a table with that name but a lot of tables with AspNet prefix like AspNetRoles. Maybe the error is somewhere else? – Lóri Nóda May 28 '14 at 15:34
  • It's easier to simply take the file created by LocalDB and restore it to SQL Server. That way you know you have everything required. For example, you may be missing some rows from the `__MigrationHistory` table. – DavidG May 28 '14 at 15:36
  • Unfortunately I'm getting the same error after the restore. Any other thought? – Lóri Nóda May 29 '14 at 07:27
  • So changing the connection string back to localdb still works? Can you share the string your using for SQL Server perhaps? – DavidG May 29 '14 at 07:45
  • Also, can you post your context class (MyCustomDBEntities) – DavidG May 29 '14 at 07:59
  • Should the DB context contain the mapping of the DB table. Recently I changed to the upper code. But I'm getting the same erros. – Lóri Nóda May 29 '14 at 08:45
  • What does your connection string look like? – DavidG May 29 '14 at 08:49
  • Which works: – Lóri Nóda May 29 '14 at 08:52
  • @DavidG thank you again for the good response, unfortunetly I'm stucked again, maybe you can take a look at my latest question. Thanks in advance! http://stackoverflow.com/questions/23951859/owin-oauth-2-0-bearer-token-never-expire – Lóri Nóda May 30 '14 at 12:03

1 Answers1

6

I suspect the problem is with your connection string. First of all, the constructor of your context only needs to have the name of the connection string, so you can change it to this:

public MyCustomDBEntities() : base("ConnectionStringName") { }

Secondly, this might just be you editing your code before you post, that name needs to match the name in the config file:

<add name="ConnectionStringName" providerName="System.Data.SqlClient" connectionString="...." />

Finally, you likely need to change your connection string to use standard SQL Server format and not EF format. So it will probably look something like this:

Data Source=LNODA-PC;Initial Catalog=Dashboard;Persist Security Info=True;User Id=XXXX;Password=XXXXXX;MultipleActiveResultSets=True;
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • Huh, this working just fine, thank you. Can you recommend me some articles which I should read about this topic because as you can see I'm a little dummy in the topic. – Lóri Nóda May 29 '14 at 09:06
  • My problem was that I was using the EF format connection string. Thanks! – Francisco G Aug 10 '16 at 13:27