A sequence contains more than one Mvc element

Problem Function The following is the function I am having problems with. I keep getting the error "sequence contains more than one element". That's what it is. However, I am not sure how to return the information so that I can use it. Any help would be greatly appreciated.

EditCountyViewModelis a small class containing the public County countyCountyList . I have also tried changing the Read<> toRead` public list , which is the base class for all 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();

        }

It seems to me that I need another class to handle the elements coming from the table countyproductand products.

+4
source share
1 answer

SingleOrDefault() , , . FirstOrDefault(), .

+22

Source: https://habr.com/ru/post/1526433/


All Articles