C# 如何编写复杂的SQL但使用谓词(通过Dapper)

C# 如何编写复杂的SQL但使用谓词(通过Dapper),c#,sql,dapper,predicate,C#,Sql,Dapper,Predicate,我将Dapper库与sqlserver一起使用。是否可以将谓词与复杂Sql查询一起使用来传递所需的参数,以便将Sql结果集过滤到单个实体类中 SELECT * FROM Config.Country INNER JOIN Config.State ON Config.State.CountryId = Config.Country.CountryId 实体类可以具有以下结构 public sealed class CountryStateReadDto { //Country ta

我将
Dapper
库与
sqlserver
一起使用。是否可以将
谓词
复杂Sql查询一起使用
来传递所需的参数,以便将Sql结果集过滤到
单个实体类中

SELECT * FROM Config.Country 
INNER JOIN Config.State 
ON Config.State.CountryId = Config.Country.CountryId
实体类可以具有以下结构

public sealed class CountryStateReadDto
{
    //Country table
    public byte CountryId { get; set; }
    public string CountryName { get; set; }
    public string CountryCode { get; set; }
    public string ISOCode { get; set; }
    public string DailingCode { get; set; }
    public string WebCode { get; set; }
    public double Longitude { get; set; }
    public double Latitude { get; set; }

    //State table
    public short StateId { get; set; }
    public string StateName { get; set; }
}
我知道,有一个漂亮的项目可以完成这项工作,但仅限于
单个表

我需要编写
复杂Sql查询
,最好使用
谓词
。有人可以帮我提供一些提示,甚至解决方案也会很有帮助

<> > <代码>谓词< /代码>不是一个理想的解决方案,那么还有什么我可以考虑还是比<代码>谓词< /代码>

更好? 注意:上面的Sql示例只是一个简单的查询,我有复杂的 具有>10个表联接的查询


我建议创建一个视图

Create View StateDetails
SELECT * FROM Config.Country 
INNER JOIN Config.State 
ON Config.State.CountryId = Config.Country.CountryId

一旦设置了视图,使用Dapper就变得容易多了。

这很有意义!