我有两个表VEHICLE和PASSENGER。车辆可容纳多名乘客。因此PASSENGER表具有vehicleId列。我需要过滤并排序显示按乘客人数显示车辆的视图。
VehicleEntity和PassengerEntity用于映射到基础。
public class VehicleEntity
{
public virtual long DbId {get; set;}
public virtual string licence {get; set;}
public virtual ISet<PassengerEntity> Passengers {get; set;}
}
public class VehicleEntityMap : ClassMap<VehicleEntity>
{
Table("Vehicle");
Id(x => x.DbId)
Map(x => x.licence);
HasMany(x => x.Passengers).KeyColumn("VehicleDbID).Inverse();
}
和旅客实体
public class PassengerEntity
{
public virtual DbId {get; set;}
public virtual VehicleEntity Vehicle {get; set;}
}
public class PassengerEntityMap : ClassMap<PassengerEntity>
{
Table("Passenger");
Id(x => x.DbId)
References(p => p.Vehicle).Column("VehicleDbId).Index("IXFK_Passenger_Vehicle");
HasMany(x => x.Passengers).KeyColumn("VehicleDbID).Inverse();
}
我通过使用以下方法管理了过滤器部分:
VehicleEntity v = null;
PassengerEntity p = null;
IQueryOver<VehicleEntity , VehicleEntity > orderQuery=
context.Session.QueryOver<VehicleEntity >(() => o);
orderQuery = orderQuery.Left.JoinAlias(() => o.Vehicles, () => v);
subQuery = QueryOver.Of<PassengerEntity>(() => p)
.Where(() => p.Vehicle.DbId == v.DbId)
.ToRowCountQuery();
orderFilterQuery = orderQuery.WithSubquery.WhereValue(2).Eq(sbuQuery);
现在我需要根据乘客人数按升序/降序对车辆进行排序。
答案 0 :(得分:0)
您可以使用$client_id = 'xxx';
$refresh_token='xxx';
$client_secret='xxx';
function GetRefreshedAccessToken($client_id, $refresh_token, $client_secret)
{
$url_token = 'https://www.googleapis.com/oauth2/v4/token';
$curlPost = 'client_id=' . $client_id . '&client_secret=' . $client_secret . '&refresh_token='. $refresh_token . '&grant_type=refresh_token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = json_decode(curl_exec($ch), true);
print_r($data);
exit;
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($http_code != 200)
{
throw new Exception('Error : Failed to refresh access token');
}
return $data;
}
add_action('wpcf7_before_send_mail', 'save_application_form');
function save_application_form($wpcf7) {
$client_id = 'xxx';
$refresh_token='xxx';
$client_secret='xxx';
global $wpdb;
$wpcf7 = WPCF7_ContactForm :: get_current() ;
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$submited = array();
$submited['title'] = $wpcf7->title();
$submited['posted_data'] = $submission->get_posted_data();
$uploaded_files = $submission->uploaded_files();
$cf7_file_field_name = 'file-846';
$image_location = $uploaded_files[$cf7_file_field_name];
$test = pathinfo($image_location);
}
GetRefreshedAccessToken($client_id, $refresh_token, $client_secret);
$token = GetRefreshedAccessToken($client_id, $refresh_token, $client_secret);
$url = "https://www.googleapis.com/upload/drive/v3/files?uploadType=media";
$headers = array(
"Content-Type: image/jpeg",
"Authorization: Bearer ".$token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
//$data1 = '@'.realpath('./metadata.json').';type=application/json;charset=UTF-8';
//$data2 = '@'.realpath('./test.csv').';type=text/csv';
$postdata = array(
'file' => file_get_contents($image_location)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$output = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $output;
}
}
对.OrderBy()
使用相同的子查询。 (顺便说一句,如果您像在示例中那样过滤记录,那么按乘客人数排序不会做太多,因为您只会得到乘客人数相同的记录。)
Projection
生成的SQL将类似于:
orderQuery.OrderBy(Projections.SubQuery(subQuery)).Asc;