I have a class called DataPoint
that is defined like the following. Currently, it goes through each property on an object and based on the DataPoint
, it does some formatting like padding, trimming, etc... before it will save the record to the database. The current implementation makes a database call for each property
which is slow, so my first step is to get everything at once into an in-memory collection. What else can I do below? Is this a good candidate for a singleton since the data rarely changes and/or is it possible to cache it (if so, how)?
public class DataPoint
{
public string Name {get;set;}
public string Justification {get;set;}
public int MaxLength {get;set;}
public string Format {get;set;}
public DataPoint GetDataPoint(string name)
{
var dataPoint =
db.Query<DataPoint>("SELECT * FROM DataPoint WHERE name = @name", new {name}).FirstOrDefault();
return dataPoint;
}
public T FormatObj<T>(T obj)
{
foreach (var propertyInfo in typeof(T).GetProperties())
{
var dataPoint = GetDataPoint(propertyInfo.Name);
//Do formatting on obj Properties such as setting values, etc...
}
return obj;
}
}
Aucun commentaire:
Enregistrer un commentaire