readonly - Why does Linq need a setter for a 'read-only' object property? -


i'm using linq datacontext.executequery("some sql statement") populate list of objects

var incomes = db.executequery<incomeaggregate>(sqlincomestatement(timeunit)); 

the incomeaggregate object made hold result of records of query.

one of properties of object yqm:

public int year { get; set; } public int quarter { get; set; } public int month { get; set; }  public string yqm  {      { return string.format("y{0}-q{1}-m{2}", year, quarter, month); }  } ... more properties 

everything compiles ok, when executes linq following error:

cannot assign value member 'yqm'. not define setter.

but clearly, don't want 'set' it. y, q , m provided query database. yqm not provided query. need change definition of object somehow? (i've started using linq , i'm still getting speed, simple)

well, wound making setter private

public string yqm {          {          return string.format("y{0}-q{1}-m{2}", year, quarter, month);      }      private set { ;}  } 

seems work.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -