简体   繁体   English

映射Servicestack.OrmLite中的字段类型

[英]map field types in Servicestack.OrmLite

Lets say I have a field in the DB with possible values 'Y', 'N', NULL. 可以说我在数据库中有一个字段,可能的值为“ Y”,“ N”,NULL。 I want to represent it in my DTO with a boolean property ('N', NULL -> false, 'Y' - > true). 我想用布尔属性('N',NULL-> false,'Y'-> true)在DTO中表示它。 Can I somehow plug into OrmLite to make the conversion myself (both directions, ofc) during the query/update/insert? 我可以在查询/更新/插入过程中以某种方式插入OrmLite来自己进行转换(两个方向,ofc)吗? Thanks 谢谢

ORMLite uses simple POCOs so you can do something like this: ORMLite使用简单的POCO,因此您可以执行以下操作:

public class MyDto
{
    // Values: Y, N, and NULL
    public string SomeDbField { get; set; }

    [Ignore]
    public bool SomeDbFieldAccessor
    {
        get { return (SomeDbField != null && SomeDbField == "Y"); }
        set { SomeDbField = value ? "Y" : "N"; }
    }
}

The [Ignore] attribute on the accessor field will tell ORMLite that the field should not be saved to / read from the database. 访问者字段上的[Ignore]属性将告诉ORMLite该字段不应保存到数据库或从数据库中读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM