scw*_*scw 23 mapping postgresql dapper
有很多方法可以将数据库字段名称映射到类名,但是删除下划线的最简单方法是什么?
public IEnumerable<PersonResult> GetPerson(int personId)
{
using (var dbConnection = _dbConnectionFactory.Create(ConnectionStrings.ProjectXYZ))
{
IEnumerable<PersonResult> result =
dbConnection.Query<PersonResult>("fn_get_person", new { personId },
commandType: CommandType.StoredProcedure).ToList();
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
表和数据库字段:
person
--------
person_id
full_name
Run Code Online (Sandbox Code Playgroud)
有效的类:(小巧玲珑已经忽略大写)
public class PersonResult
{
public int Person_Id { get; set; }
public string Full_Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想把课程改为:
public class PersonResult
{
public int PersonId { get; set; }
public string FullName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*ell 48
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
Run Code Online (Sandbox Code Playgroud)
完成工作; p
| 归档时间: |
|
| 查看次数: |
5235 次 |
| 最近记录: |