Better ways to build a linq specification for querying or is this the only way? The code pretty much explains what I am doing here. Just wondering if anyone can think of a better way.

public class AttachmentQuery
{
    /// &lt;summary&gt;
    /// Initializes a new instance of the &lt;see cref="AttachmentQuery"/&gt; class.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;param name="status"&gt;The status.&lt;/param&gt;
    /// &lt;param name="sort"&gt;The sort.&lt;/param&gt;
    /// &lt;param name="order"&gt;The order.&lt;/param&gt;
    /// &lt;param name="page"&gt;The page.&lt;/param&gt;
    public AttachmentQuery(string type, string status, SortAttachment sort, SortOrder order, int? page)
    {
        IAttachmentSpecification specification = null;

        if (!string.IsNullOrEmpty(type))
        {
            specification = new AttachmentFileTypeSpecification(type);
        }

        if (!string.IsNullOrEmpty(status))
        {
            if (specification == null)
            {
                specification = new AttachmentStatusSpecification(status.AsEnum&lt;AttachmentStatus&gt;());
            }
            else
            {
                var spec = new AndSpecification&lt;Attachment&gt;(
                    specification, 
                    new AttachmentStatusSpecification(status.AsEnum&lt;AttachmentStatus&gt;())
                );

                specification = spec as IAttachmentSpecification;
            }
        }

        if (specification == null)
        {
            specification = new AttachmentSpecification();
        }

        specification.Page = page;
        specification.Limit = Setting.AttachmentPageLimit.Value;
        specification.Sort = sort;
        specification.Order = order;

        this.Specification = specification;
    }

    /// &lt;summary&gt;
    /// Gets or sets the specification.
    /// &lt;/summary&gt;
    /// &lt;value&gt;The specification.&lt;/value&gt;
    public IAttachmentSpecification Specification
    {
        get;
        private set;
    }
}


Source.

How it is used.
I would definitely write it differently but exact result depends on whether your AndSpecification supports only two parameters or it can accept IEnumerable of attachments. 

If it has two parameters and you expect to nest those AndSpecifications if you will have more specs to compose then I would write something like this:  

var typeSpecification = string.IsNullOrEmpty(type) ? null : new AttachmentFileTypeSpecification(type);
var statusSpecification = string.IsNullOrEmpty(status) ? null : new AttachmentStatusSpecification(status.AsEnum&lt;AttachmentStatus&gt;());
var specificationsToCompose = new IAttachmentSpecification[] {typeSpecification, statusSpecification};

var composedSpecification = specificationsToCompose
                     .Aggregate((IAttachmentSpecification) null, (accumulator, currentSpec) =&gt;
                         {
                             if (accumulator != null &amp;&amp; currentSpec != null) return new AndSpecification&lt;Attachment&gt;(accumulator, currentSpec);
                             return accumulator ?? currentSpec;
                         })
                      ?? new AttachmentSpecification();

...

this.Specification = composedSpecification;