I use Entity Framework 6, database first. There are automatically generated entities like this:

public partial class PutlZeroMileage { public long ID { get; set; } public Nullable<System.DateTime> Date { get; set; } public Nullable<int> FK_ZM { get; set; } public Nullable<decimal> KmFact { get; set; } public Nullable<decimal> FctBeginTime { get; set; } public Nullable<decimal> FctEndTime { get; set; } public string ControlPointB { get; set; } public string ControlPointE { get; set; } public Nullable<bool> Consider { get; set; } public Nullable<long> FK_Putl { get; set; } public Nullable<int> Time { get; set; } public virtual Putl Putl { get; set; } public virtual ZeroMileage ZeroMileage { get; set; } } 

Properties are bound to columns in a datagrid. It is necessary that when you change one of the properties (for example FctBeginTime) change Time. In theory, the set FctBeginTime properties can be recalculated Time, and call PropertyChanged. But this is the generated code, the regeneration will erase everything. How to do it better?

    1 answer 1

    1. Your class is marked as partial, make another part in which you declare the properties notifying of the change, and the receiving / recording data here in these generated properties. In the table through Binding bind your properties with the notification of the change.

      public partial class PutlZeroMileage: INotifyPropertyChanged {

       public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName]string propertyName = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public Nullable<decimal> BeginTime { get { return FctBeginTime; } set { if (value != FctBeginTime) { FctBeginTime = value; CalcTime(); OnPropertyChanged(); OnPropertyChanged(nameof(Time)) } } } 

      }

    2. Make a class a wrapper in which this will be a field with an instance of your class from the database, and in the public part there will be only those properties that you need in the user interface, you already make them correct, and they store the data in the model class.