Base solution for your next web application
Open Closed

EntityFramework.DynamicFilter Bug #1910


User avatar
0
marcosli created

Hi,

EF DynamicFilter versions 2.3.x or 2.4.x has a bug when entities mappings are done like this:

public class CustomUserPermissionMap : EntityTypeConfiguration<CustomUserPermission>
    {
        public CustomUserPermissionMap()
        {
            HasKey(x => x.Id);

            HasRequired(x => x.User)
                .WithMany()                
                .Map(x => x.MapKey("UserId"))
                .WillCascadeOnDelete(false);

            HasRequired(x => x.RolePermissionSetting)
                .WithMany()
                .Map(x => x.MapKey("RolePermissionId"))                
                .WillCascadeOnDelete(false);
        }
    }

To make it work, i had to change my mapping to this:

public class CustomUserPermissionMap : EntityTypeConfiguration<CustomUserPermission>
    {
        public CustomUserPermissionMap()
        {
            HasKey(x => x.Id);

            HasRequired(x => x.User)                
                .WithMany()
                .HasForeignKey(x => x.UserId)                
                .WillCascadeOnDelete(false);

            HasRequired(x => x.RolePermissionSetting)
                .WithMany()                
                .HasForeignKey(x => x.RolePermissionId)
                .WillCascadeOnDelete(false);
        }
    }

The exception message is this: System.ApplicationException : FK Constriant not found for association 'EFDynamicFilter.EntityFramework.CustomUserPermission_User' - must directly specify foreign keys on model to be able to apply this filter

The second way of mapping entities were working perfectly in EF DynamicFilter 1.4.x. My guess is, that exception occurs when the kind of hierarchy is TPH.

If you need a sample demo, i could send to your e-mail.

Thanks.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you have a sample project for this, it would be great if you send it to us.

    Thanks for your work.

  • User Avatar
    0
    marcosli created

    Hi,

    I've sent an email to <a href="mailto:[email protected]">[email protected]</a> with the link to the application.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you for sharing the project. We will try it soon.

    By the way, we are thinking of downgrading to DynamicFilters v1.14 because of this issue which is not solved in DynamicFilters v2.x yet and it seems like it's not going to be solved in a short time. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1433">https://github.com/aspnetboilerplate/as ... ssues/1433</a>