在linq中使用委托

public List<Profile> GetProfileList(StockInParam param)
{
    using (var db = new guideDB())
    {
        Expression<Func<Profile, bool>> filter = p => p.Status == 2;
        if (!param.TimeStart.ToString().IsNullOrEmpty())
            filter = filter.And(ao => ao.CreatedOn >= param.TimeStart);
        if (!param.TimeEnd.ToString().IsNullOrEmpty())
            filter = filter.And(ao => ao.CreatedOn <= param.TimeEnd);
        if (param.PurchaseArrivedType > 0)
            filter = filter.And(ao => ao.ArrivedType == param.PurchaseArrivedType);
        if (!param.ProfileID.IsNullOrEmpty())
            filter = filter.And(ao => ao.ProfileID.Contains(param.ProfileID));
        if (!param.ReceiptNumber.IsNullOrEmpty())
            filter = filter.And(ao => ao.TrackingNumber.Contains(param.ReceiptNumber));
        if (!param.PurchaeArea.IsNullOrEmpty())
            filter = filter.And(ao => ao.RegionName == param.PurchaeArea);

        return db.Profiles
                    .Where(filter)
                    .OrderByDescending(ao => ao.CreatedOn).Take(200).ToList();
    }
}

你可能感兴趣的:(在linq中使用委托)