Datatables .NET property mapping

Datatables .NET property mapping

rauntskarauntska Posts: 5Questions: 2Answers: 0
edited August 2018 in General

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

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    Use:

    .Field(new Field("Status")
      .Get(false)
      .Set(false)
    

    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

  • rauntskarauntska Posts: 5Questions: 2Answers: 0

    Hi,

    Yes id like to use this "Status" property elsewhere( in UI ). But the value of the property is calculated in backend .

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    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

  • rauntskarauntska Posts: 5Questions: 2Answers: 0

    This worked- Thanks !!

This discussion has been closed.