简体   繁体   中英

C# Custom Setter Entity Framework 6.1.3

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.

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM