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

Samples of CosmosDb usage #13200

Closed
jcagme opened this issue Sep 4, 2018 · 3 comments

Comments

@jcagme
Copy link

commented Sep 4, 2018

I'm using Microsoft.EntityFrameworkCore.Cosmos.Sql Version 2.2.0-preview1-35029 for EF driven identity in asp.net core 2.1.

I've added identity to some projects in the past but this is the first attempt using CosmosDb. Pretty much, I've done what is described here: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1.

When running dotnet ef migrations add initial or dotnet ef database update I get:

Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Migrations.IMigrator'. This is often because no database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

The error is the same even if I add a design time factory. My DB context class like this:

namespace Proj.Data
{
    public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
    {
        public ApplicationDbContext CreateDbContext(string[] args)
        {
            DbContextOptions options = new DbContextOptionsBuilder().UseCosmosSql(
                    new Uri("https://uri.documents.azure.com:443/"),                
                    "key",
                    "db-name")
                .Options;
            return new ApplicationDbContext(options);
        }
    } 

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

        public DbSet<Customer> Customers { get; set; }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<Customer>()
                .HasIndex(t => new {t.Id})
                .IsUnique();
        }
    }
}

What is wrong with this class? Is there an article I can follow as an example to get this working?

@ajcvickers

This comment has been minimized.

Copy link
Member

commented Sep 5, 2018

@jcagme Migrations are designed around relational databases and hence IMigrator is not available. Issue #6983 is tracking a better exception message for these cases. We do have ideas around evolving the document database, but these will likely not look like relational migrations.

We will be blogging about Cosmos DB very soon. This should help showing how to use it and what currently works. Please keep in mind that this is still very much a preview and many things are not yet supported.

@umar-qureshi2

This comment has been minimized.

Copy link

commented Apr 24, 2019

Is there any documentation related to migrations with versioning?
I have a custom tool for now that does the job when needed.

@ajcvickers

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

@umar-qureshi2 Migrations are a relational concept. There is no support for them when using the Cosmos provider. We have some ideas for things we might be able to do in the future around similar scenarios, but that is beyond the current goals for the Cosmos provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.