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.


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

  • User Avatar
    0
    kirtik created

    sure . will share now.Thanks.

  • User Avatar
    0
    kirtik created

    @maliming Shared the project with you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi kirtik

    I will check as soon as possible. : )

  • 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));
    	}
    }
    
  • User Avatar
    0
    kirtik created

    @maliming Thanks for the solution.

    How do i resolve this error ?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @kirtik

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

  • User Avatar
    0
    kirtik created

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    using Volo.Abp.Domain.Entities;

  • User Avatar
    0
    kirtik created

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

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi Maybe it is using System;

  • User Avatar
    0
    kirtik created

    Yes. That worked !! Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

  • User Avatar
    0
    kirtik created

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

    But the dbcontext exists here.....

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Are you sure the Cosmos need migrations?

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

  • 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

  • User Avatar
    0
    kirtik created

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

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    @kirtik 👍

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09