NHibernate sub query on Orders filtering by usergroup

by Joe Payne 17. March 2014 09:31

A client had a need to filter the Monthly Sales Summary report by group membership.  In other words, restrict the totals to orders placed by users only in a specific user group.

The initial NHibernate query is such:

ICriteria criteria = NHibernateHelper.CreateCriteria<CommerceBuilder.Orders.Order>("O")
    .CreateCriteria("Items", "OI", NHibernate.SqlCommand.JoinType.InnerJoin)
    .Add(Restrictions.Eq("O.Store", AbleContext.Current.Store));

 

So I added a dropdown that is populated by GroupDataSource.LoadAll().  Then it seemed easy enough to just add this code which I found in the UserSearchCriteria.cs file:

if (groupId >= 0)
{
    criteria.CreateCriteria("O.User.UserGroups", "UG", NHibernate.SqlCommand.JoinType.InnerJoin)
    .Add(Restrictions.Eq("UG.Id.Group.Id", this.GroupId));
}

The problem is, this code throws a big ol’ NHibernate error “nhibernate multi-part identifier <someobject> could not be bound”

For some reason, NHibernate couldn’t resolve the relationship of Order –> User –> UserGroups –> Group.   The code I swiped from UserSearchCriteria had no problem with it.  But here it just wouldn’t work.

I finally figured out the solution was to create a new reference to the User table and base the criteria from there.   So instead of starting at the Order object level, the join and restriction starts as the User object level which sort of makes sense now that I’m typing this…

if (groupId >= 0)
{
    criteria.CreateCriteria("O.User", "U", NHibernate.SqlCommand.JoinType.InnerJoin)
        .CreateCriteria("U.UserGroups", "UG")
        .Add(Restrictions.Eq("UG.Id.Group.Id", groupId));
}

Finally, the end result is the NHibernate query now properly searches the orders for only those records where the user that placed the order is a member of a specific GroupId.

Tags: , , , ,

AbleCommerce Gold | Personal

Server 2012 how to set folder permissions ASP.Net application pool

by Joe Payne 5. March 2014 09:26

Microsoft tries so hard to make things simple, yet often winds up making them harder. 

I needed to set folder permissions with an ASP.Net 4.0 website running on Server 2012.   The problem was the site worked, but certain folders needed Modify rights.

To make this happen properly, you have to:

1.  Locate the name of the application pool assigned to your asp.net website.  In my case, we’ll call it BlahAppPool.  You can find which app pool is assigned by using IIS Manager and going to the Basic Settings of the website in question.

2.  Now that you know the name of the app pool, the trick to setting folder permissions in Server 2012…

You must add the credentials as IIS APPPOOL\BlahAppPool

You won’t see it listed if you do a search.  It’s a virtual account.  Every app pool gets a virtual account in Server 2012.  And make sure you have the space between IIS and APPPOOL.

Once you get it added, now you can check the Modify right and save.   You remembered to propagate permissions to child objects didn’t you?

Tags: , , , ,

Personal | Tech Support

Month List