Deal with Readonly values in ASP.NET (Core) applications and Azure Tables -
i have object this:
class record { public datetime created { get; set; } // ? set or not set ? public string name { get; set; } public record() : (datetime.now) { } public record(datetime created) { this.created = created; } }
my problem don't know how expose created
member, read-only get;
or set;
?
that member set once when created (by constructor), should readonly viewed.
in edit view have problems field, because if expose them writeable (with set
) input tries update or says it's wrong formatted; other side if readonly not load database (azure tables in case)...
here function recuperates records "database" (azure tables):
public async task<list<t>> gettableentitiesasync<t>(string partition) t : itableentity, new() { tablequery<t> recordsquery = new tablequery<t>().where( tablequery.generatefiltercondition("partitionkey", querycomparisons.equal, partition)); list<t> mylist = new list<t>(); var items = await this.gettable<t>().executequerysegmentedasync<t>(recordsquery, null); mylist = items.tolist(); return mylist; // when readonly records have created == datetime.now }
you may use 2 models:
simple dto class storing to/retrieving db
class dbrecord { public datetime created { get; set; } public string name { get; set; } }
business model specific logic time handling
class record { public datetime created { get; private set; } public string name { get; set; } public record() { this.created = datetime.now;} public record(dbrecord dbrecord) { this.name = dbrecord.name; this.created = dbrecord.created; } }
Comments
Post a Comment