MissioDei
MissioDei

Reputation: 809

How do you do this in a calculated property

In my MVC 3 app I have the following

public class SalesPerson
 {
      public SalesPerson()
    {
        this.SalesOrders = new HashSet<SalesOrder>();
        this.Ups = new HashSet<Up>();
    }

    public int SalesPersonId { get; set; }
    public int StoreId { get; set; }
    public Store Store { get; set; }

 public string StoreAndCode
    {
         get 
         {
              return Store.Code + ", " + Store;
         }
    }

I am assuming that I have to instantiate the store in the return statement in order to actually get the code and name for the return? How would I write this so I can expose this in the corresponding view?

Upvotes: 0

Views: 106

Answers (1)

Jim D&#39;Angelo
Jim D&#39;Angelo

Reputation: 3952

Set your property to virtual.

public class SalesPerson
{
    ...
    public virtual Store Store { get; set; }
}

Upvotes: 1

Related Questions