我们正在寻找Dapper来简化我们的映射逻辑。除了一件事,它看起来很有前途。我们为ID使用自定义类型。例如:
public class MyEntityIdentity
{
public int IdentityValue { get; }
public MyEntityIdentity(int identity) { IdentityValue = identity; }
}
public class MyEntity
{
public MyEntityIdentity Identity { get; set; }
int Prop1 { get; set; }
string Prop2 { get; set; }
bool Prop3 { get; set; }
}
SQL表看起来像这样:
create table [dbo].[MyEntity] (
my_entity_id int identity(1,1) NOT NULL,
prop1 int NULL,
prop2 varchar(100) NULL,
prop3 bit NOT NULL
CONSTRAINT PK_MyEntity PRIMARY KEY CLUSTERED (my_entity_id ASC)
)
我们如何映射“身份”属性?
答案 0 :(得分:1)
您可以像这样使用自定义类型处理程序:
SqlMapper.AddTypeHandler(new IdentityHandler());
并像这样注册它:
> as.numeric(test$posix)
[1] 1456963200 1457222400 1456876800 1446595200 1446422400
[6] 1453161600 1453248000 1466121600 1459814400 1437350400
[11] 1456272000 1444176000 1455148800 1460073600 1456617600
[16] 1456704000 1453852800 1453507200 1461196800 1458259200
[21] 1455667200 1454889600 1460246400 1454371200 1459814400
[26] 1455062400 1445904000 1451520000 1449878400 1460419200