Yes you can do that but you'll have to write the translation code yourself. But I will start by saying that I wouldn't recommend doing this in the controller itself. If you need any sort of reuse then your controller should call an intermediate "service" class to handle the work of talking to the DB. If you absolutely must do it directly on the context then consider adding an extension method that handles the details for you.
Let's start with the simple case. If you need to "transform" a value in the DB to something else then a simple property on the base type is sufficient.
public class SalesRegion
{
//Backed by DB
public string SalesReportFilters { get; set; }
public string FormattedFilter
{
get {
if (SalesReportFilters.Contains("MM"))
//Parse data and return it
//Return original value
}
}
}
public async Task<ActionResult> GetReportConditions(String region)
{
var output = _db.GetSalesRegions.where(x => x.region == region)
.Select(x => new
{
salesData = x.FormattedFilter
}).ToArrayAsync();
return new JsonResults(output);
}
If you need to do work that requires more than the instance itself holds then you'll have to write that out yourself. An extension method can be used here to make it reusable elsewhere.
public static class SalesRegionExtensions
{
public static IEnumerable<SalesRegion> GetSalesRegionsWithFilters ( this DbContext context, string region )
{
var items = _db.GetSalesRegions.Where(x => x.region == region);
foreach(var item in items)
{
//Set the "salesData" on the SalesRegion based upon the condition
item.SalesData = item.SalesReportFilter;
if (/*whatever condition determines you need to run a query*/)
{
var results = _db.GetWhateverData(...);
item.SalesData = //hook up results
};
};
return items;
}
}
The caveat here is that you can attach the results of the extra query to the original region data that is being returned. If that isn't an option then you might need to introduce a grouping type (or use a tuple or pair) to associate the original sales region with the results of the query.