Open Closed

Abp With Ef Core can't prevent foreign key generation #3752


User avatar
0
selinkoykiran created

Hello , We have different aggregate roots , they have a relation over Id property like below :

Project first aggregate:

Phase second aggregate :

created migration with foreign key:

Like you saw in the pictures , even we try NotMapped attribute , still migration is creating foreign key automagically :) Depends on your framework suggestions and DDD , we don't want to generate foreign key between aggregate roots , instead we keep them seperately, we just want to saw ProjectId column inside Phase table not foreign key relation . But we can not do that right know it's always creating itself , we can't understand the situation.

Below example is from an outside-native ef core in a console application, when we don't use abp-wrapped ef core, they can prevent the generation of foreign key , if we ignore the navigation property , they don't create the foreign key. We're expecting the same approach basically.

What can we do about this situation ? Thank you

  • ABP Framework version: v5.3.3
  • UI type: MVC
  • DB provider: EF Core
  • **Tiered (MVC) : yes

4 Answer(s)
  • User Avatar
    0
    selinkoykiran created

    Hello , Anyone checked this issue ? Just a reminder :)

    Thank you.

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Can you share the Fluent API configuration under onModelCreating for the Phase entity?

    public class Project : AuditedAggregateRoot<Guid>, IMultiTenant
    {
        public Guid? TenantId { get; protected set; }
        public string Name { get; protected set; }
        public string Description { get; protected set; }
        public Guid BaseModelId { get; protected set; }
    }
    
    public class Phase : AuditedAggregateRoot<Guid>, IMultiTenant
    {
        public Guid? TenantId { get; protected set; }
        public Guid ProjectId { get; protected set; }
        public string Name { get; protected set; }
        public string Description { get; protected set; }
    }
    

    Only added DbSets and no fluent API configuration: Although, you don't need to implement IHasExtraProperties for the AggregateRoot since it already implements it.

  • User Avatar
    0
    selinkoykiran created

    Thank you for the IExtraProperties information. I'm sharing the fluentapi part :

    As I shared at first post , even I ignore ProjectId column , it's still creating fk with ProjectId1 ? Thank you .

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Since it is auto-generated by the EfCore, either Project has navigation for Phase or your owned entities have some relation with the Project entity.

    This is not related to ABP but the EfCore itself. If you can share a public repository with the same problem, I can check. Otherwise, there seems no problem with the screenshot.

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