Skip to content
This repository was archived by the owner on Dec 29, 2020. It is now read-only.
This repository was archived by the owner on Dec 29, 2020. It is now read-only.

Map private or protected properties #466

@frankiDotNet

Description

@frankiDotNet

It is often so,that you want to load something from the database but you want to handle it only in the class. Maybe some basic calculations or a certain way for handling with nummeric enum values that don't exist.
In this case you would use a public property that works with the private or protected field. From outside the class the db field does not have to be changed directly.
For example:

public enum MyColor{
 Red = 0,
 Blue = 1,
 Green = 2
}
[Column("StatusId")] // This won't work
private Int32 ColorValue {get; set;}

public MyColor Color {
    get{  
        if(Enum.IsDefined(typeof(MyColor), ColorValue))
            return (MyColor)ColorValue;

        return MyColor.Green;
    }
    set{
        ColorValue = (Int32)value;
    }
}

I this case you are forced to make everthing public although you don't want to make it accessable directly.
I mean there could be a configuration parameter to enable private mapping or maybe protected mapping.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions