tags:

views:

24

answers:

1

I'm trying to get a Wrapper from NHibernate with the following code:

    public Wrapper GetWrapper(int siteId, string actionName)
    {
        Wrapper wrapper = _session.CreateCriteria<Wrapper>()
            //.Add(SqlExpression.Like<Wrapper>(xx => xx.SiteId, siteId))                
            .Add(SqlExpression.Equals(xx => xx.SiteId, siteId))
            .Add(SqlExpression.Like<Wrapper>(xx => xx.Action, actionName))
            .List<Wrapper>().FirstOrDefault();

        return wrapper;
    }

The bit that's commented out:

.Add(SqlExpression.Like<Wrapper>(xx => xx.SiteId, siteId))

is inefficient. I need to get the Wrapper where the Wrapper.SiteId == siteId, not where it's Like siteId. I should note that siteId is not a primary key. Can somebody please tell me what I can do to improve this? Thanks

A: 

This worked:

    public Wrapper GetWrapper(int siteId, string actionName)
    {
        Wrapper wrapper = _session.CreateCriteria<Wrapper>()
            .Add<Wrapper>(x => x.SiteId == siteId)
            .Add<Wrapper>(x => x.Action == actionName)
            .List<Wrapper>().FirstOrDefault();

        return wrapper;
    }
DaveDev