Serenity

Use Expression Attribute in Serenity

Use Expression Attribute in Serenity

Expressions

Expression attribute is used to specify expression of a non-basic field, e.g. one that doesn't actually exist in database.


public class UserRow : Row
{
    public string Firstname
    {
        get { return Fields.Firstname[this]; }
        set { Fields.Firstname[this] = value; }
    }

    public string Lastname
    {
        get { return Fields.Lastname[this]; }
        set { Fields.Lastname[this] = value; }
    }

    [Expression("(T0.[Firstname] + ' ' + T0.[Lastname])")]
    public string Fullname
    {
        get { return Fields.Fullname[this]; }
        set { Fields.Fullname[this] = value; }
    }
}

-- main table is assigned T0 alias in Serenity queries



Can use Expression Using Dynamic SQl Queries


public class UserRow : Row
{
    [DisplayName("Courtesy"), Size(25)]
    public string TitleOfCourtesy
    {
        get => fields.TitleOfCourtesy[this];
        set => fields.TitleOfCourtesy[this] = value;
    }


    [DisplayName("Gender"), Expression("(CASE WHEN T0.[TitleOfCourtesy] LIKE '%s%' THEN 2 WHEN T0.[TitleOfCourtesy] LIKE '%Mr%' THEN 1 END)")]
    public Gender? Gender
    {
        get { return (Gender?)Fields.Gender[this]; }
        set => fields.Gender[this] = (int?)value;
    }
}








Related Post

About Us

Community of IT Professionals

A Complete IT knowledgebase for any kind of Software Language, Development, Programming, Coding, Designing, Networking, Hardware and Digital Marketing.

Instagram