从QueryMultiple结果中获取字符串值

时间:2017-07-28 12:02:32

标签: model-view-controller .net-core

在我的dotNetCore项目中,我有一个使用QueryMultiple返回多个结果集的查询...

这是我的查询

var sql = @"SELECT CountryId as Id, CountryName as Name FROM country;
            SELECT CityId as Id, CityName as Name, CountryId FROM city;
            SELECT CitizenshipId as Id, CitizenshipName as Name FROM citizenship;
            Select Count(user.UserId) as totalUserCount
                            FROM identityuser user;";

这就是我将结果变为变量

的方法
 using (IDbConnection dbConnection = new DbManager().Connection)
            {
                dbConnection.Open();

                var grid = dbConnection.QueryMultiple(sql, new
                {
                });

                manageProfileView.countries = grid.Read<Country>().ToList();
                manageProfileView.cities = grid.Read<City>().ToList();
                manageProfileView.nationalities = grid.Read<CitizenShip>().ToList();
            }

现在我怎样才能获得此查询的数据

  

选择Count(user.UserId)作为totalUserCount                                   来自identityuser用户;

我尝试过这样的事情

  

var userCount = grid.Read()。ToList();

但它没有返回有效数据,有没有更好的方法从grid变量获得简单计数。

1 个答案:

答案 0 :(得分:1)

我相信您只需要获得相应的列表计数,请尝试:

var userCount = grid.Read().ToList().Count;