Open Closed

Switch to Azure Cosmos for Entity Framework Core #660


User avatar
0
kirtik created

I am performing a proof of concept for using Azure Cosmos DB. I am following these steps to use Azure Cosmos DB from mvc/jquery ABP.IO application. https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Other-DBMS I am at the last step of "Re-Generate the Migrations". However i started getting exceptions for many tables for the concurrencyStamp property which i resolved one by one by using the IsETagConcurrency() and it worked for all entities so far. But its not working for the <ApiResource> entity.

I tried ignoring the entity but still getting the same error. Its not ignored at all. Maybe since its defined in the matadata ?

<br> Could you please help me since i think my Azure Cosmos will work if this issue is resolved.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

19 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi kirtik

    Maybe you don't need to configure one by one.

    Can you share with me a sample project using Azure Cosmos DB? I can check it.

    liming.ma@volosoft.com

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    sure . will share now.Thanks.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    @maliming Shared the project with you

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi kirtik

    I will check as soon as possible. : )

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi kirtik

    You can try this.

    protected override void OnModelCreating(ModelBuilder builder)
    {
    	base.OnModelCreating(builder);
    
    	/* Include modules to your migration db context */
    
    	builder.ConfigurePermissionManagement();
    	builder.ConfigureSettingManagement();
    	builder.ConfigureBackgroundJobs();
    	builder.ConfigureAuditLogging();
    	builder.ConfigureIdentity();
    	builder.ConfigureIdentityServer();
    	builder.ConfigureFeatureManagement();
    	builder.ConfigureTenantManagement();
    	builder.UseCosmos();
    
    
    	/* Configure your own tables/entities inside the ConfigureBookStore method */
    
    	builder.ConfigureBookStore();
    
    	foreach (var entityType in builder.Model.GetEntityTypes())
    	{
    		ConfigureETagConcurrency(builder, entityType);
    	}
    }
    
    private void ConfigureETagConcurrency(ModelBuilder modelBuilder, IMutableEntityType mutableEntityType)
    {
    	if (mutableEntityType.IsOwned())
    	{
    		return;
    	}
    
    	if (!typeof(IEntity).IsAssignableFrom(mutableEntityType.ClrType))
    	{
    		return;
    	}
    
    	var entityTypeBuilder = modelBuilder.Entity(mutableEntityType.ClrType);
    
    	if (entityTypeBuilder.Metadata.ClrType.IsAssignableTo<IHasConcurrencyStamp>())
    	{
    		entityTypeBuilder.Property(nameof(IHasConcurrencyStamp.ConcurrencyStamp))
    			.IsETagConcurrency()
    			.HasMaxLength(ConcurrencyStampConsts.MaxLength)
    			.HasColumnName(nameof(IHasConcurrencyStamp.ConcurrencyStamp));
    	}
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    @maliming Thanks for the solution.

    How do i resolve this error ?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @kirtik

    The png you shared is not clear. Can you share the text?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    using Volo.Abp.Domain.Entities;

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    No it is not resolved. I have already referenced -- using Volo.Abp.Domain.Entities;

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi Maybe it is using System;

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    Yes. That worked !! Thanks

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    Getting this error when i run Add.migration command in console.

    But the dbcontext exists here.....

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Are you sure the Cosmos need migrations?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    same error with update-database. I need to be able to migrate the Book entity from this project to Azure Cosmos.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi kirtik

    I am not familiar with Cosmos, but it does not seem to need to migrate and update the database.

    https://docs.microsoft.com/en-us/ef/core/providers/cosmos/?tabs=dotnet-core-cli

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    kirtik created

    Yes @maliming . I am thinking too. Let me go through the link . Thnaks for your support .

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    @kirtik 👍

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 23, 2026, 09:57
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.