問題函數 下面是我遇到的問題。我不斷收到「序列包含多個元素」的錯誤。這是假設。但是,我不確定如何返回信息,以便我可以使用它。任何幫助,將不勝感激。序列包含多個元素Mvc
EditCountyViewModel
是一個小類,它包含public County county
public List CountyList . I have also tried changing the Read<> to
Read`這是我所有縣信息的基類。
public EditCountyViewModel FindByCounty(string countyName)
{
var parameters = new DynamicParameters();
parameters.Add("@CountyName", value: countyName);
var query = @"SELECT counties.id
, counties.CountyName
, counties.Website
, counties.Address
, counties.City
, counties.State
, counties.PhonePrimary
, counties.PhoneAlt
, counties.RecordsOnline
, counties.BackToYear
, counties.Cost
, products.ProductName
, products.Description
, countyproduct.TurnTime_MinHours
, countyproduct.TurnTime_MaxHours
, countyproduct.Price
FROM
counties, countyproduct, products
WHERE
counties.CountyName = @CountyName AND countyproduct.countiesID = countyproduct.countiesID AND countyproduct.productsID = products.ID;";
//using (var multi = this.db.QueryMultipl(query, new { countyName }))
//{
// EditCountyViewModel editVM = new EditCountyViewModel();
// editVM.county = multi.Read<County>().Single();
// return editVM;
//}
return this.db.Query<EditCountyViewModel>(query, parameters).SingleOrDefault();
}
我想我需要另一個類來處理從countyproduct
& products
表未來的項目。
哪條線給你這個錯誤? – Blorgbeard
返程線。但在註釋掉的代碼中,'editVM.county = multi.Read().Single();'給了我錯誤 –
MaylorTaylor
sql看起來很有趣。 countyproduct.countiesID = countyproduct.countiesID是打算? – smiggleworth