C# Dapper UPPER 函数
C# Dapper UPPER functions
我正在使用 Dapper C# .Net Core 6.0 MVC
查询;
var query = $"SELECT d.Id,d.CityId,d.CountryId,UPPER(d.Name) FROM District as d INNER JOIN City as c ON d.CityId = c.Id Where c.Id={Convert.ToInt32(id)}";
var result = conn.Query<CityDto>(query).ToList();
数据获取但 d.Name 的值为空
当我在 SQL 服务器
中执行它时它有效
我的错误在哪里?
Dapper关心列名,UPPER(d.Name)
为匿名列;考虑使用 as
作为列的别名:
var result = conn.Query<CityDto>(@"
SELECT d.Id, d.CityId, d.CountryId, UPPER(d.Name) as [Name]
FROM District as d
INNER JOIN City as c ON d.CityId = c.Id
Where c.Id=@id", new { id }).AsList();
注意我还修复了参数用法。
我正在使用 Dapper C# .Net Core 6.0 MVC
查询;
var query = $"SELECT d.Id,d.CityId,d.CountryId,UPPER(d.Name) FROM District as d INNER JOIN City as c ON d.CityId = c.Id Where c.Id={Convert.ToInt32(id)}";
var result = conn.Query<CityDto>(query).ToList();
数据获取但 d.Name 的值为空
当我在 SQL 服务器
中执行它时它有效我的错误在哪里?
Dapper关心列名,UPPER(d.Name)
为匿名列;考虑使用 as
作为列的别名:
var result = conn.Query<CityDto>(@"
SELECT d.Id, d.CityId, d.CountryId, UPPER(d.Name) as [Name]
FROM District as d
INNER JOIN City as c ON d.CityId = c.Id
Where c.Id=@id", new { id }).AsList();
注意我还修复了参数用法。