Это ошибка: CS1061 C # не содержит определения для 'Query', и нет доступного метода расширения 'Query', принимающего первый аргумент типа (вы пропустили директиву using или ссылку на сборку?)
Вот мои модели
public class TourPackage
{
public int p_id { get; set; }
public string p_name { get; set; }
public string p_price { get; set; }
public string p_category { get; set; }
public string p_bedroom { get; set; }
public List<InclusionList> inclusionLists { get; set; }
public List<ConditionList> conditionLists { get; set; }
public List<Exclusions> exclusiions { get; set; }
public List<Flights> flights { get; set; }
public List<Itineray> itinerays { get; set; }
public List<TDates> dates { get; set; }
public List<sliders> sliders { get; set; }
public List<Visareq> visareqs { get; set; }
}
public class InclusionList
{
public int in_id { get; set; }
public int p_id { get; set; }
public string in_name { get; set; }
}
public class ConditionList
{
public int co_id { get; set; }
public int p_id { get; set; }
public string co_name { get; set; }
}
public class Exclusions
{
public int ex_id { get; set; }
public int p_id { get; set; }
public string ex_name { get; set; }
}
public class Flights
{
public int fl_id { get; set; }
public int p_id { get; set; }
public string fl_name { get; set; }
}
public class Itineray
{
public int it_id { get; set; }
public int p_id { get; set; }
public string it_name { get; set; }
public int bmeal { get; set; }
public int lmeal { get; set; }
public int dmeal { get; set; }
}
public class TDates
{
public int td_id { get; set; }
public int p_id { get; set; }
public string td_fdate { get; set; }
public string td_tdate { get; set; }
}
public class sliders
{
public int img_id { get; set; }
public int p_id { get; set; }
public string img_slides { get; set; }
}
public class Visareq
{
public int vi_id { get; set; }
public string vi_name { get; set; }
}
public class Bedtype
{
public int bed_id { get; set; }
public string bedtype { get; set; }
}
public class Category
{
public int c_id { get; set; }
public string c_type { get; set; }
}
Это запрос, который я пробовал
public static List<TourPackage> LoadPackageData()
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
string sql = @"select pt.p_id, pt.bedroom, pt.c_id, pt.p_name, pt.p_price,
br.bedtype,
ca.c_type,
inc.name,
co.name,
ex.name,
fl.name,
it.name, it.description, it.bmeal, it.lmeal, it.dmeal,
tr.dfrom, tr.dto,
vi.name,
img.slides
from dbo.t_package as pt
left join bedrooms as br on pt.bedroom = br.bed_id
left join category as ca on pt.c_id = ca.c_id
left join inclusion as inc on pt.p_id = inc.p_id
left join condition as co on pt.p_id = co.p_id
left join exclusion as ex on pt.p_id = ex.p_id
left join flightdetails as fl on pt.p_id = fl.p_id
left join itinerary as it on pt.p_id = it.p_id
left join traveldates as tr on pt.p_id = tr.p_id
left join visareq as vi on pt.p_id = vi.p_id
left join imagetable as img on pt.p_id = img.p_id
order by pt.p_id;";
var query = con.Query<TourPackage, Bedtype, Category, InclusionList, ConditionList, Exclusions, Flights, Itineray, TDates, sliders, Visareq, TourPackage>(sql,
(tr, bt, ca, inc, co, ex, fl, it, td, sl, vi) =>
{
tr.bedroom = bt;
tr.c_id = ca;
tr.p_id = inc;
tr.p_id = co;
tr.p_id = ex;
tr.p_id = fl;
tr.p_id = it;
tr.p_id = td;
tr.p_id = sl;
tr.p_id = vi;
return tr;
}, splitOn: "bed_id, c_id, p_id, p_id, p_id, p_id, p_id, p_id, p_id, p_id");
return query;
}
}
Я пытался найти много решений, но ошибка все ещетам.
Вот мои таблицы базы данных
create table bedrooms (
bed_id int primary key identity(1,1) not null,
bedtype varchar(50) not null
);
create table category (
c_id int identity(1,1) primary key not null,
c_type varchar(100) not null
);
create table t_package (
p_id int primary key identity(1,1) not null,
p_name varchar(100) not null,
p_price float,
c_id int,
foreign key (c_id) references category(c_id),
bedroom int,
foreign key(bedroom) references bedrooms(bed_id)
);
create table inclusion (
in_id int identity(1,1) primary key not null,
name varchar(150) not null,
p_id int,
foreign key (p_id) references t_package(p_id)
);
create table condition (
con_id int primary key identity(1,1) not null,
name varchar(150) not null,
p_id int,
foreign key (p_id) references t_package(p_id)
);
create table exclusion (
ex_id int primary key identity(1,1) not null,
name varchar(150) not null,
p_id int,
foreign key(p_id) references t_package(p_id)
);
create table flightdetails (
fl_id int primary key identity(1,1) not null,
name varchar(100) not null,
p_id int,
foreign key (p_id) references t_package(p_id)
);
create table itinerary (
it_id int primary key identity(1,1) not null,
name varchar(100) not null,
description text,
bmeal int,
lmeal int,
dmeal int,
p_id int,
foreign key (p_id) references t_package(p_id)
);
create table traveldates (
tdates_id int primary key identity(1,1) not null,
dfrom date,
dto date,
p_id int,
foreign key (p_id) references t_package(p_id)
);
create table imagetable (
img_id int primary key identity(1,1) not null,
img_header varchar(500),
img_sliders text,
p_id int,
foreign key (p_id) references t_package(p_id)
);
create table visareq
(
visa_id int primary key identity(1,1) not null,
name varchar(150),
p_id int,
foreign key (p_id) references t_package(p_id)
);
Это изображение данных моего пакета, это только один пакет, но содержит список деталей, таких как маршрут и т. Д.
Я создаю отдельный файл, который представляет собой Query.cs в качестве контейнера запросов, но когда я выполняю сопоставление с несколькими таблицами, я столкнулся с этой ошибкой, поэтому я решил поместитьмое сопоставление с несколькими таблицами в моем Connect.cs с методом LoadPackageData (), но ошибка все еще там.
Вот мой Connect.cs
using Dapper;
using DataLibrary.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataLibrary.Connection
{
public class Connect
{
public static string GetConnectionString(string connection = "mycon")
{
return ConfigurationManager.ConnectionStrings[connection].ConnectionString;
}
public static int SaveBedType<B>(string sql, B data)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
return con.Execute(sql, data);
}
}
public static int SaveSlide<S>(string sql, S data)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
return con.Execute(sql, data);
}
}
public static int SaveCategory<C>(string sql, C data)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
return con.Execute(sql, data);
}
}
public static List<B> LoadData<B>(string sql)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
return con.Query<B>(sql).ToList();
}
}
public static List<DDP> LoadDDPackage<DDP>(string sql)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
return con.Query<DDP>(sql).ToList();
}
}
//public static List<TP> LoadPackageData<TP, INC, CO, EX, FL, IT, TD, SL, VI, RS>(string sql, object param)
//{
// using (IDbConnection con = new SqlConnection(GetConnectionString()))
// {
// var q = con.Query<TP, INC, CO, EX, FL, IT, TD, SL, VI, RS>(sql,
// (tr, inc, co, ex, fl, it, td, sl, vi, tl) => { tr.p_id = inc; return tr; });
// return q;
// }
//}
public static List<TourPackage> LoadPackageData()
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
const string sql = @"select pt.p_id, pt.bedroom, pt.c_id, pt.p_name, pt.p_price,
br.bedtype,
ca.c_type,
inc.name,
co.name,
ex.name,
fl.name,
it.name, it.description, it.bmeal, it.lmeal, it.dmeal,
tr.dfrom, tr.dto,
vi.name,
img.slides
from dbo.t_package as pt
left join bedrooms as br on pt.bedroom = br.bed_id
left join category as ca on pt.c_id = ca.c_id
left join inclusion as inc on pt.p_id = inc.p_id
left join condition as co on pt.p_id = co.p_id
left join exclusion as ex on pt.p_id = ex.p_id
left join flightdetails as fl on pt.p_id = fl.p_id
left join itinerary as it on pt.p_id = it.p_id
left join traveldates as tr on pt.p_id = tr.p_id
left join visareq as vi on pt.p_id = vi.p_id
left join imagetable as img on pt.p_id = img.p_id
order by pt.p_id;";
var query = con.Query<TourPackage, Bedtype, Category, InclusionList, ConditionList, Exclusions, Flights, Itineray, TDates, sliders, Visareq, TourPackage>(sql,
(tr, bt, ca, inc, co, ex, fl, it, td, sl, vi) =>
{
tr.bedroom = bt;
tr.c_id = ca;
tr.p_id = inc;
tr.p_id = co;
tr.p_id = ex;
tr.p_id = fl;
tr.p_id = it;
tr.p_id = td;
tr.p_id = sl;
tr.p_id = vi;
return tr;
}, splitOn: "bed_id, c_id, p_id, p_id, p_id, p_id, p_id, p_id, p_id, p_id");
return query;
}
}
public static List<C> LoadCategory<C>(string sql)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
return con.Query<C>(sql).ToList();
}
}
public static int SavePackage(string sql, DynamicParameters p)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
con.Execute(sql, p);
return p.Get<int>("@Id");
}
}
public static int SaveTDates(DataTable d)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var dates = new
{
travelDates = d.AsTableValuedParameter("DateUDT")
};
return con.Execute("dbo.TravelDateInsert", dates, commandType: CommandType.StoredProcedure);
}
}
public static int SaveItinerary(DataTable i)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var details = new
{
itinerary = i.AsTableValuedParameter("MyUDT")
};
return con.Execute("dbo.Itinerary_insert", details, commandType: CommandType.StoredProcedure);
}
}
public static int SaveFlightDetails(DataTable f)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var flights = new
{
flightDetails = f.AsTableValuedParameter("FlightDUDT")
};
return con.Execute("dbo.FlightDetails_insert", flights, commandType: CommandType.StoredProcedure);
}
}
public static int SaveConditions(DataTable tc)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var condition = new
{
terms_conditions = tc.AsTableValuedParameter("ConditionUDT")
};
return con.Execute("dbo.Condition_insert", condition, commandType: CommandType.StoredProcedure);
}
}
public static int SaveExclusion(DataTable e)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var exclusion = new
{
exclusions = e.AsTableValuedParameter("ExclusionUDT")
};
return con.Execute("dbo.Exclusion_insert", exclusion, commandType: CommandType.StoredProcedure);
}
}
public static int SaveVisareq(DataTable v)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var visa = new
{
visareq = v.AsTableValuedParameter("VisaReqUDT")
};
return con.Execute("dbo.VisaReq_insert", visa, commandType: CommandType.StoredProcedure);
}
}
public static int SaveInclusion(DataTable _in)
{
using (IDbConnection con = new SqlConnection(GetConnectionString()))
{
var inclusion = new
{
inclusions = _in.AsTableValuedParameter("InclusionUDT")
};
return con.Execute("dbo.Inclusion_insert", inclusion, commandType:CommandType.StoredProcedure);
}
}
}
}