Datatables .NET property mapping
Datatables .NET property mapping
Hi,
Im using the Editor .NET version.
How can i Define a property in my model that's not in the database table. I would manually define the value for this. But however it seems that the Editor wants to map it from the database and results in and error where it says invalid column.
Here's my model:
public class WorkHoursModel
{
public string TABN { get; set; }
public string Date { get; set; }
public string FingerStart { get; set; }
public string ProdmanStart { get; set; }
public string ScheduleStart { get; set; }
public string FingerEnd { get; set; }
public string ProdmanEnd { get; set; }
public string ScheduleEnd { get; set; }
public string FormulaStart { get; set; }
public string FormulaEnd { get; set; }
public string Duration { get; set; }
public string Status{get;set;}// NOT a DATABASE column
}
//Actionresult
using (var db = new Database(ConfigurationReader.GetDatatablesConnectionType(),ConfigurationReader.GetConnectionString(ConfigurationReader.ConnectionType.ISABDB_NEFAB_AXAPTA_EE5)))
{
var response = new Editor(db, "NPTime_WorkHours","TABN")
.Model<WorkHoursModel>()
.Field(new Field(nameof(WorkHoursModel.Date))
.GetFormatter(Format.DateSqlToFormat("dd.MM.yyyy")))
.Field(new Field(nameof(WorkHoursModel.FingerStart))
.GetFormatter((val, row) => val ?? "Puudub"))
.Field(new Field(nameof(WorkHoursModel.ProdmanStart))
.GetFormatter((val, row) => val ?? "Puudub"))
.Field(new Field(nameof(WorkHoursModel.FingerEnd))
.GetFormatter((val, row) => val ?? "Puudub"))
.Field(new Field("ProdmanEnd")
.GetFormatter((val, row) => val ?? "Puudub"))
.Field(new Field("Duration")
.GetFormatter(Format.DateSqlToFormat("HH:mm:ss"))
)
// NB !- how can i define the value for the Status propery here ?
.Where("TABN",1211,"=")
.Process(request)
.Data();
return Json(response);
}
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use:
If it isn't a db value, and you aren't manually adding it in the controller, is there any need for it? Or are you using the model elsewhere as well?
Allan
Hi,
Yes id like to use this "Status" property elsewhere( in UI ). But the value of the property is calculated in backend .
Use
Field.GetValue()
in that case. That method can be used to compute the value for the field in the JSON data. API doc.Allan
This worked- Thanks !!