C# Custom Setter Entity Framework 6.1.3

724 Views Asked by At

I've tried searching for an answer to this question but maybe my google skills are slacking (it is Wednesday after all).

I want to use a custom setter like this.

public class ITEMViewModel
{
    public ITEM_ACTIVE ITEMDATA { get; set; }
    private string _ThumbnailUNC;
    public string ThumbnailUNC
    {
        get
        {
            return _ThumbnailUNC;
        }
        set
        {
            _ThumbnailUNC = FileLocation.getThumb(value);
        }
    }
}

That works great as long as I do something like this.

    ae.ITEM_ACTIVE
         .Where(x => x.ORG == Org && x.PART_NUMBER == PN)
         .Select(x => new ITEMViewModel
         {
              ITEMDATA = x,
              ThumbnailUNC = x.PART_NUMBER //This is the important part
         })
         .FirstOrDefault();

What I want to do is this.

set
{
   _ThumbnailUNC = FileLocation.getThumb(ITEMDATA.PART_NUMBER); //Not value
}

ae.ITEM_ACTIVE
         .Where(x => x.ORG == Org && x.PART_NUMBER == PN)
         .Select(x => new ITEMViewModel
         {
              ITEMDATA = x
         })
         .FirstOrDefault();

The second way always returns null (It's never setting?) Is there any way to always have that setter run when I populate ITEMDATA?

I'm fairly new to custom setters and getters so any reference would be greatly appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

You're doing it on the wrong property.

private ITEM_ACTIVE _itemData;
public string ThumbnailUNC { get; private set; }
public ITEM_ACTIVE ITEMDATA 
{ 
    get 
    {
        return _itemData;
    }
    set
    {
        _itemData = value;
        ThumbnailUNC = value.PART_NUMBER;
    }
}