Open Closed

About Many to Many relationship for Different Module template #1607


0
abpVAndy created
  • ABP Framework version: v4.3.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

Could you please give me more ideas/examples how to create the relationship for different Modules. It will not hard if in same module. But for the different module, the class has to use other module's class, which will cause some issues.

Thanks,

Scenario: I use suite to create two Module template: 1, CategoryCenter, 2, ProductCenter

In CategoryCenter, I have two aggregate: Brand, and CategoryEnd. In ProductCenter, I have one aggregate: Product.

Product could have many brand, so it was M:M relationship. product could have many category, so it was M:M relationship.

I follow the OrganizationUnit of Identity to create the relationship for them.

So, in productcenter, I create two entity: ProductBrand, ProductCategory which is the other tables. And I add them into product aggregate, see below picture.

And In ProductCenterDbContextModelCreatingExtensions, I configure like OrganizationUnit of Identity. see below picutures.

When I execute: add-migration ..... it has below error: The property 'Brand.ExtraProperties' could not be mapped because it is of type 'ExtraPropertyDictionary', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.


6 Answer(s)
  • 0
    liangshiwei created
    Support Team

    Hi,

    Do these two modules use the same database? if yes, you can try call the builder.ConfigureCategoryCenter in the ProductCenterDbContext

  • 0
    abpVAndy created

    Thanks for your reply. Yes, we use one database. We already have tried it. It will not create that issue, but we dev module one by one. The categorycenter already finished and create tables in db. So, if we call builder.ConfigureCategoryCenter, it will create category tables one more time. and update-database will not pass for the tables already in db.

    1, if we use your method, to call builder.ConfigureCategoryCenter in productcernterdbcontext, do we need to delete the duplicate tables from Migration file? Is this common method to deal with this Scenario?

    2, I used suite to create navigation property. I konw xxxWithNavigationProperties class was used as the bridge class of relationship of 1:M. So for M:M relastionship, is it possible we could use like xxxWithNavigationProperties class to make M:M bridge?

    3, Could you give me some ideas or examples for the M:M in microservices. You know, M:M is very common in Microservice, like shippmentcenter with ordercenter. order also is M:M with shippment. and Order with payment some Scenario also need M:M.

    Thanks,

  • 0
    abpVAndy created

    I follow your method to test it. 1, add builder.ConfigureCategoryCenter in the ProductCenterDbContext 2, add-migration --> create new migration file 3, remove these category tables from this migration file (these tablse are already in db) 4, update-database --> it works

    Another question: It is about the "AutoMapperProfile". Can we use category automapperprofile directly in the productcetner module?

    Now I want to use CategoryCenterApplicationAutoMapperProfile in productcenter module. I have to copy the info of CategoryCenterApplicationAutoMapperProfile into productcenter module.

    Without copy, it dose not work.

    Thx

  • 0
    liangshiwei created
    Support Team

    Could you give me some ideas or examples for the M:M in microservices. You know, M:M is very common in Microservice

    Maybe you can create a shared entityframemworkcore project, since they use the same database, why not use the same database context, which will make development easier

    Can we use category automapperprofile directly in the productcetner module?

    Same solution, create a shared application.contract project.

  • 0
    abpVAndy created

    Thanks.

    I will consider your advice.

  • 0
    albert created
    Support Team

    closing the issue. reopen it if your issue will not be fixed