I am trying to use [Serializable] attribute with a PetaPoco Entity so it can be stored in a REDIS Cache.
Adding the [Serializable] attribute to the PetaPoca Entity class allows it to be cached with a REDIS Caching provider but then changes the way the WebAPI serializes the Entity to JSON which breaks.
Is there a way to specify how the WebAPI serializes the object to JSON?
Examples below, for specifics this is within the DAL2 for DNN and using the https://github.com/davidjrh/dnn.rediscachingprovider REDIS Caching Provider for DNN.
DNN DAL2 / PetaPoco Object:
[TableName("sbCurrencyRates")]
//setup the primary key for table
[PrimaryKey("CurrID", AutoIncrement = true)]
//configure caching using PetaPoco
[Cacheable("sbCurrencyRates", CacheItemPriority.Default, 20)]
//scope the objects to the ModuleId of a module on a page (or copy of a module on a page)
[Serializable]
public class CurrRateInfo
{
public int CurrID { get; set; }
public string CurrCode { get; set; }
public double CurrRate { get; set; }
public DateTime LastUpdate { get; set; }
}
WebApi Controller:
public class RatesController : DnnApiController
{
[AllowAnonymous]
[HttpGet]
public HttpResponseMessage GetRates()
{
CurrRatesController crc = new CurrRatesController();
return Request.CreateResponse(HttpStatusCode.OK, crc.Get());
}
}
Thanks in advance.