小巧的半动态打字?

时间:2017-06-30 19:20:50

标签: sql-server dapper

我有一个类似架构的表:

CREATE TABLE [dbo].[Property](
[id] [uniqueidentifier] NOT NULL,
[PropertyOccupantTypeId] [uniqueidentifier] NULL,
[PropertyStatusId] [uniqueidentifier] NOT NULL
-- Other potential columns
)

它有很多查找值,我的用户不需要知道任何事情。他们只需要PropertyStatus而不是PropertyStatusId

假设查找表各有2列(guid:id,varchar:value)有没有办法编写类似于的查询:

SELECT p.id,
       po.value as OccupantType,
       ps.value as PropertyStatus
       -- Other potential columns
FROM Property p 
     join PropertyOccupantType po on p.PropertyOccupant = po.id 
     join PropertyStatus ps on p.PropertyStatusId = ps.id

并将该地图设置为Property对象,如下所示:

public class Property
{
    public Guid id;
    public string PropertyOccupant;
    public string PropertyStatus;
}

或者我是否需要手动查询其他表并以这种方式映射值?

1 个答案:

答案 0 :(得分:2)

这应该可以正常工作。 Dapper不关心你写的是什么查询。它只是将结果集中的列名与对象的属性名匹配。

相关问题