我正在尝试查询所有国家和每个国家/地区的对象,它会填满各省。
我有以下课程
public class Country
{
public int Countryid { get; set; }
public string CountryName { get; set; }
public IEnumerable<Province> Provinces { get; set; }
}
public class Province
{
public int ProvinceId { get; set; }
public string ProvinceName { get; set; }
}
public IEnumerable<Country> GetCountries()
{
var query = @"
SELECT [Country].[CountryId], [Country].[Name] as CountryName, [Province].[ProvinceId], [Province].[Name] as ProvinceName
FROM [Province]
RIGHT OUTER JOIN [Country] ON [Province].[CountryId] = [Country].[CountryId]
WHERE [Country].[CountryId] > 0";
return _connection.Query<Country, Province, Country>(query, (country, province) =>
{
country.Provinces = country.Provinces.Concat(new List<Province> { province });
return country;
}, null);
}
我得到的错误如下:
System.ArgumentException:'当使用多映射API时,如果您具有Id以外的键,请确保设置splitOn参数 参数名称:splitOn'
我一直在关注这个例子:
https://gist.github.com/Lobstrosity/1133111
从我的角度来看,除了我作为外部联接之外,我没有看到我做了多少不同的事情,我认为无关紧要,结果格式大致相同。
为什么我需要拆分,没有它可以工作吗?
答案 0 :(得分:2)
[client-profile.notls]
client-id="burrow-test"
kafka-version="1.0.0"
我在LinqPad中输入了这个,所以你需要调试并检查它是否正确,自从我在愤怒中使用Dapper以来已经很久了