Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How/Where to apply business rules to POCO objects?

Let's say I have a POCO with the following:

    [DataMember]
    public Nullable<int> MetricId
    {
        get { return _metricId; }
        set
        {
            if (_metricId != value)
            {
                _metricId = value;
                OnPropertyChanged("MetricId");
            }
        }
    }
    private Nullable<int> _metricId;

I want to validate that the MetricId is strictly greater than 0

Obivously, if I put this rule as a data annotation in this class it will be overwritten the next time I regen the poco. Where do I put this logic?

Thanks!

like image 271
O.O Avatar asked Apr 12 '11 18:04

O.O


1 Answers

I seem to remember the suggestion being to utilize partial classes and roll a partial class that implemented the logic you didn't want to be overwritten.

like image 198
Khepri Avatar answered Nov 09 '22 06:11

Khepri