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

Invalid object name 'Application' #44

Closed
Gillardo opened this issue Jan 8, 2016 · 11 comments
Closed

Invalid object name 'Application' #44

Gillardo opened this issue Jan 8, 2016 · 11 comments
Labels

Comments

@Gillardo
Copy link

Gillardo commented Jan 8, 2016

I have finally got my application running on rc2 (brand new web application so i can test your software).

Now i have followed all the steps on the readme and my project builds. Problem is that this run in my startup.cs file is causing an error.

if (!context.Applications.Any())

When this line executes my sql database is created, but the Application table is completely missing? I have deleted my database and started again multiple times, but it never gets created. I have tried both database setup options, inheriting from OpenIddictContext and including the Application DbSet on an existing IdentityDbContext object. Neither seem to work??

I am using SQLServer, here is an example of my connectionString, which i believe is fine

"ConnectionString": "Server=(local);Database=OpenIdDictDb;Trusted_Connection=True;"

Here is an image of my database tables, as you can see the Application table is not created.

image

@kevinchalet
Copy link
Member

Have you tried the samples?

@Gillardo
Copy link
Author

Gillardo commented Jan 8, 2016

I have not, i wanted to start with a clean project to start with, so i could follow everything. I can try a sample project, which one do i need, Server or Client?

@Gillardo
Copy link
Author

Gillardo commented Jan 8, 2016

Right, i have narrowed the problem down, and found out what is causing the error. Not sure if this is my mistake, or whether the readme file needs to be updated. In a default webApplication, this appears in the startup.cs file.

if (env.IsDevelopment())
{
    app.UseBrowserLink();
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage();
}
else
{
    app.UseExceptionHandler("/Home/Error");

    // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
    try
    {
        using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
            .CreateScope())
        {
            serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
                 .Database.Migrate();
        }
    }
    catch { }
}

I have not got my site in development mode, so it is calling the Database.Migrate() method. I am not sure why the Application table is not created, because this is being called, but this is the reason.

Can someone shed some light on this?? I havent used EF7 yet, so not sure what is right/wrong

@singlewind
Copy link

Make sure your application DataSet is inside your ApplicationDbContext and the OnModelCreating has code to create the application table. If database already exists, you need create the migration code as well.

@Gillardo
Copy link
Author

Dbset added as tried inheriting from openid context as well as using own
and it compiles successfully.

Database didnt exist so would expect Application table to be created like
all other tables are
On 9 Jan 2016 23:41, "Yue Zhou" notifications@github.com wrote:

Make sure your application DataSet is inside your ApplicationDbContext and
the OnModelCreating has code to create the application table. If database
already exists, you need create the migration code as well.


Reply to this email directly or view it on GitHub
#44 (comment).

@Gillardo
Copy link
Author

This was an issue with the DI. All sorted now

@bouchepat
Copy link

Can you explain how you sorted it out? Tried with new project and run the examples but still getting the same error. Invalid Applications object.

Thanks

@bouchepat
Copy link

Might exists a better solution, but this fixed the issue:

public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{ }

    public DbSet<Application> Applications { get; set; }
}

Hopefully this can help others.

@kevinchalet
Copy link
Member

Might exists a better solution, but this fixed the issue:

Nope, it's the right approach if you don't want to inherit from OpenIddictContext. It's clearly mentioned in the README:

image

@bouchepat
Copy link

Thanks, I read the readme and it did help resolving the issue; however the readme does not mention if inheriting from OpenIddictContext the Applications table will not be created. Which is the issue reported.
If there is a reason why the table is not created when inheriting from OpenIddictContext I would be interested to know why. Thanks

@kevinchalet
Copy link
Member

If there is a reason why the table is not created when inheriting from OpenIddictContext I would be interested to know why.

Hum weird. Are you sure you didn't have a pre-existing database before updating your context class to inherit from OpenIddictContext?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants