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
Closed

Samples of CosmosDb usage #13200

jcagme opened this issue Sep 4, 2018 · 3 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@jcagme
Copy link

jcagme 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
Copy link
Member

@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.

@ajcvickers ajcvickers added closed-no-further-action The issue is closed and no further action is planned. customer-reported labels Sep 5, 2018
@umar-qureshi2
Copy link

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

@ajcvickers
Copy link
Member

@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.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants