Example #1
0
        private IEnumerable <T> GetByFilter <T>(List <FilterExpressionInfo> filterExpressionInfos) where T : class
        {
            using (NHibernateRepository <T> repository = new NHibernateRepository <T>(ConnectionString, DomainAssemblyName))
            {
                var parameter = Expression.Parameter(typeof(T));
                BinaryExpression binaryExpressionBody = null;
                foreach (var filterExpressionInfo in filterExpressionInfos)
                {
                    var property  = Expression.PropertyOrField(parameter, filterExpressionInfo.PropertyToFilter);
                    var exprRight = Expression.Constant(filterExpressionInfo.Value);
                    BinaryExpression binaryExpression = null;
                    switch (filterExpressionInfo.FilterExpressionType)
                    {
                    case FilterExpressionType.Equal:
                        binaryExpression = Expression.Equal(property, exprRight);
                        break;
                    }
                    if (binaryExpressionBody == null)
                    {
                        binaryExpressionBody = binaryExpression;
                    }
                    else
                    {
                        binaryExpressionBody = Expression.AndAlso(binaryExpressionBody, binaryExpression);
                    }
                }
                Expression <Func <T, bool> > lambda = Expression.Lambda <Func <T, bool> >(binaryExpressionBody, parameter);

                return((IEnumerable <T>)repository.FindBy(lambda));
            }
        }
Example #2
0
 public T FindBy <T>(int id) where T : class
 {
     using (IRepository <T> repository = new NHibernateRepository <T>(ConnectionString, DomainAssemblyName))
     {
         return(repository.FindBy(id));
     }
 }