public IQueryable <preg_my_belly> GetItemsByParams(preg_my_belly data) { IQueryable <preg_my_belly> result = connect.preg_my_belly; for (int i = 0; i < data.GetType().GetProperties().ToList().Count(); i++) { string propertyName = data.GetType().GetProperties().ToList()[i].Name; var propertyValue = data.GetType().GetProperty(propertyName).GetValue(data, null); if (propertyName == "id" && (int)(propertyValue) != 0) { result = result.Where(c => c.id == (int)(propertyValue)); } else if (propertyName == "image" && propertyValue != null) { result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.image) > 0); } else if (propertyName == "month" && (int)propertyValue != 0) { result = result.Where(c => c.month == (int)(propertyValue)); } else if (propertyName == "user_id" && propertyValue != null) { result = result.Where(c => c.user_id == (int)(propertyValue)); } } return(result); }