Caching Patterns in ASP.NET

后端 未结 3 1975
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 18:51

So I just fixed a bug in a framework I\'m developing. The pseudo-pseudocode looks like this:

myoldObject = new MyObject { someValue = \"old value\" };
cache.Inse         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 19:12

    A little improvement on Marks anwser when using linq:

    When using Linq, fetching entities from DB will mark every object as IsDirty. I made a workaround for this, by not setting IsDirty when the value is not set; for this instance: when null. For ints, I sat the orig-value to -1, and then checked for that. This will not work, however, if the saved value is the same as the uninitialized value (null in my example).

    private string _name;
    [Column]
    public string Name
    {
        get { return _name; }
        set
        {
            if (value != _name)
            {
                if (_name != null)
                {
                    IsDirty = true;   
                }
                _name = value;
            }
        }
    }
    

    Could probably be improved further by setting IsDirty after initialization somehow.

提交回复
热议问题