小巧型半动态打字?

问题描述:

我有一个类似的模式的表:小巧型半动态打字?

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

它有很多关于它的查找值的,我的用户并不需要知道什么。他们只需要在PropertyStatus不是PropertyStatusId

假设查找表有2列,每列(GUID:ID,VARCHAR:值)是否有写类似的查询方式:

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; 
} 

或者我需要手动查询附加表和映射这样的价值观?

这应该很好。 Dapper不在乎你写的是什么查询。它只是将结果集中的列名与对象的属性名匹配。