我的数据库中有 4 个表,即餐厅、美食、设施、菜肴。我创建了一个从这些表返回数据的表适配器。现在我必须根据用户选择的菜肴、设施或菜肴来过滤数据,并返回结果餐厅。这是我的查询:
public string alldata(string location, string cuisines, string facility)
{
location = location.Replace('|', ',');
facility = facility.Replace('|', ',');
cuisines = cuisines.Replace('|', ',');
string loc; string data = null; int id;
DataSet3.DataTable1DataTable all = getall.GetAllData();
IEnumerable<DataRow> query = from resturants in all.AsEnumerable()
where ((location.Contains(resturants.City)) && (facility.Contains(resturants.FacilityName) && (cuisines.Contains(resturants.Type))))
select resturants;
foreach (DataSet3.DataTable1Row item in query)
{
name = item.Name;
loc = item.Location;
id = item.RestaurantID;
data += name + "%" + loc +"%"+id+ "?";
}
return data;
}
此查询返回重复的条目,并且在选择中不应用 AND。我被困住了。请帮我。