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
Post a Comment