public IQueryable <preg_time_frame> GetItemsByParams(preg_time_frame data) { IQueryable <preg_time_frame> result = connect.preg_time_frame; 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 == "frame_title" && propertyValue != null) { result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.frame_title) > 0); } } return(result); }