Problem function Below is the function that i'm having issues with. I keep getting the "sequence contains more than one element" error. Which it is suppose to. However, i'm unsure how to return the information so i can use it. Any help would be appreciated.
The EditCountyViewModel
is a small class that contains public County county
public List CountyList. I have also tried changing the Read<> to
Read` which is just the base class for all of my county information.
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();
}
I think i need another class to handle the items coming from the countyproduct
& products
table.
SingleOrDefault()
makes sure there is only 1 record returned and will throw if there are more. Use FirstOrDefault()
if you just want to grab the first one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With