Base solution for your next web application
Open Closed

Help using DynamicFilter with List ( In sql clause) #522


User avatar
0
vitor lacerda created

Hi Halil,

In My Project, a User belong to 1 or + OU (Organization Unit).

Entities like "Sales" implements "IMustHaveOU" interface.

public interface IMustHaveOU { public Guid OrgUnitId {get;set;}

[ForeingKey("OrgUnitId")] public OrgUnit OrgUnit {get;set;} }

I want to create a DynamicFilter to filter entity that implement this interface using OU's from Current User (AbpSession).

So, I extend "User" class

public class User : AbpUser<Tenant, User> { public virtual ICollection<OrgUnit> OrgUnits{ get; set; } //List of OU that user belongs

    public virtual ICollection OUIds{ get; set; } //List of OU Id's that user belongs
}

The question is?

How can i get User navigation from AbpSession?

How can i use AbpSession.User.OrgUnits (List) on Dynamic filter?

protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Filter("OuFilter", (IMustHaveOU entity) => AbpSession.User.OUList.Contains(entity.OrgUnitId), null);

or

modelBuilder.Filter("OuFilter", (IMustHaveOU entity,, List placeList) =>placeList.Contains(p.PlaceId), () => AbpSession.User.OUIds);

    }

Is this a good approach? this will create a "IN" clause on SQL?

Can i extend properties on AbpSession?

Can i use LINQ JOIN in DynamicFilter?

Thanks

Vitor Lacerda


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    While it may work, I'm not sure if it's a good idea to create such a 1 to N filter (which cause a IN query on SQL). I advice to manually filter it if it will not be so hard for you. Also, if you create filter, you need to always disable it when you need to access all data.

    But, for your question;

    As you see, AbpSession only stores UserId and TenantId, which are primitive types those are easily serializable and stored in cookies (for cookie based auth). AbpSession don't use ASP.NET in-memory session, uses cookies. Thus, server becomes stateless.

    So, how to store a bigger object on the store? First of all, the problem is not just to store. Also, you can update it when user's groups changes. I suggest you to create some cache mechanism for that (and invalidate the cache for a user when user's group releations changes.) See ABP's cache document (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Caching">http://www.aspnetboilerplate.com/Pages/ ... ts/Caching</a>) I use similar caching mechanism for user permissions.