如何用fastcrud编写sql代码?

时间:2017-02-20 08:03:36

标签: dapper-fastcrud

类:

[Table("department_types", Schema = "public")]
public class DepartmentTypes


[Table("departments", Schema = "public")]
    public class Department

查询:

private string BuildQuery()
            {
                return OrmConfiguration.GetSqlBuilder<DepartmentViewModel>().Format(
                    $@" SELECT {nameof(Department.Id):C},
                                {nameof(Department.Name):C},
                                {nameof(Department.TypeId):C},
                                {nameof(DepartmentTypes.Name):C} as DepartmentTypeName
                        FROM {nameof(Department):T}
                        LEFT JOIN {nameof(DepartmentTypes):T}
                        ON {nameof(Department.TypeId):C} = {nameof(DepartmentTypes.Id):C}");
            }

结果类:

public class DepartmentViewModel
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public int TypeId { get; set; }

        public string DepartmentTypeName { get; set; }

    }

我想与Department和DepartmentTypes建立联接并获得DepartmentViewModel结果......

现在代替{nameof(DepartmentTypes):T}(例如)系统放置&#34; DepartmentViewModel&#34;,而不是DepartmentTypes的名称:&#34; department_types&#34;

1 个答案:

答案 0 :(得分:0)

我找到了答案:D。

None