Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property value changes without setter being called

I'm working on a project where a record needs to be inserted, using a context class. However, before the insertion, one of the properties 'DataArea' is being set to a value that it should not have.

I started debugging the code to see where exactly this value is being set, and I have altered the short written version of the getter and setter (get; set;), to this:

public DataAreaEnum _DataArea;
public DataAreaEnum DataArea
    {
        get
        {
            return _DataArea;
        }
        set
        {
            _DataArea = value;
            Debugger.Break();
        }
    }

By doing this, I had hoped that the debugger would break when the value was being set, however this is never hit. I am stuck and do not know how to think about this. Are there any other ways this value could have been set? How can I found out where this value was being set, if the breakpoint in the setter is never hit?

The complete class code:

using Works.Common.Models;
using System.Collections.Generic;
using System.Diagnostics;

namespace Works.Models.Toolsheets
{
    public partial class Toolblad : ModelBase
    {
        public Toolblad()
        {
            Bijlagen = new HashSet<Bijlage>();
            //Carrousels = new HashSet<Carrousel>();
            KlauwplaatSlijpers = new HashSet<KlauwplaatSlijper>();
            Klauwplaten = new HashSet<Klauwplaat>();
            Laadtafels = new HashSet<Laadtafel>();
            Laders = new HashSet<Lader>();
            MblStangenLaders = new HashSet<MblStangenLader>();
            MblStangenLaderWisselpunten = new HashSet<MblStangenLaderWisselpunt>();
            Shuttles = new HashSet<Shuttle>();
            Spankoppen = new HashSet<Spankop>();
            SpankopSlijpers = new HashSet<SpankopSlijper>();
            Revolvers = new HashSet<ToolbladRevolver>();
        }

        public DataAreaEnum _DataArea;
        public DataAreaEnum DataArea
        {
            get
            {
                return _DataArea;
            }
            set
            {
                _DataArea = value;
                Debugger.Break();
            }
        }

        public bool IsTemplate { get; set; }

        #region Navigation Properties

        public virtual AlgemeneInfo AlgemeneInfo { get; set; }

        public int AlgemeneInfoId { get; set; }

        public ICollection<Bijlage> Bijlagen { get; set; }

        //public ICollection<Carrousel> Carrousels { get; set; }

        public ICollection<KlauwplaatSlijper> KlauwplaatSlijpers { get; set; }

        public ICollection<Klauwplaat> Klauwplaten { get; set; }

        public ICollection<Laadtafel> Laadtafels { get; set; }

        public ICollection<Lader> Laders { get; set; }

        public MachineGroep MachineGroep { get; set; }

        public int MachineGroepId { get; set; }

        public ICollection<MblStangenLader> MblStangenLaders { get; set; }

        public ICollection<MblStangenLaderWisselpunt> MblStangenLaderWisselpunten { get; set; }

        public ICollection<ToolbladRevolver> Revolvers { get; set; }

        public ICollection<Shuttle> Shuttles { get; set; }

        public ICollection<Spankop> Spankoppen { get; set; }

        public ICollection<SpankopSlijper> SpankopSlijpers { get; set; }

        #endregion Navigation Properties
    }
}
like image 563
Stefan Eeckhoudt Avatar asked Mar 31 '26 17:03

Stefan Eeckhoudt


2 Answers

I note that Toolblad is a partial class. Is there any code elsewhere changing _DataArea? Try renaming it to something else (e.g. _dataArea) just in that code file and see if it all still compiles.

Doing that will catch any unexpected code that tries to access it.

like image 191
Matthew Watson Avatar answered Apr 02 '26 12:04

Matthew Watson


Whether you set the value of a Enum or not, it defaults to 0 which is why you are seeing a value for it without setting one.

like image 45
Jawad Avatar answered Apr 02 '26 11:04

Jawad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!