开发者

How to pass a parameter in my method to return using a stateless session? minimize code duplication

I want to pass a parameter in my method call, if set (its a boolean), then return a Stateless session.

I don't want to duplicate the QueryOver code, is there a way to have it like:

public virtual IList<User> GetAllUsers(bool isStateless)
{

  va开发者_JS百科r query = QueryOver<User>().Where(x => x.UserType == 1).ToList();

  if(isStateless)
    return NHibernateHelper.Session(query);
  else
    return NHibernateHelper.StatelessSession(query);

}

I know the above won't work, but I hope it is clear what I am after.

The only way I know is to basically duplicate the entire queryover code, and the only different between the code blocks will be that one will use .Session and the other will use .StatelessSession.

Hoping there is a cleaner way.


var query = QueryOver.Of<User>().Where(x => x.UserType == 1);

IQueryOver<User, User> executableQuery;
if(isStateless)
    executableQuery = query.GetExecutableQueryOver(NHibernateHelper.Session);
else
    executableQuery = query.GetExecutableQueryOver(NHibernateHelper.StatelessSession);

return executableQuery.ToList();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜