lundi 22 juin 2015

JS Datatables Editor C# API throws an exception of Data set for 'XXX' is not of type Nullable`1

I have a Product Class that has some fields that are Nullable (also in SQL Database)

public class Product
{
    public string Id { get; set; }
    public string Title { get; set; }
    public decimal? DesiredPrice { get; set; }
}

Once I initialize the Editor plugin and inline update a cell I got the following Exception: Editor C# API gives an exception of Data set for 'DesiredPrice' is not of type Nullable`1

public class ActiveController : ApiController
{
    [Route("Home/api/Active/GetActiveListings")]
    [HttpPost, HttpGet]
    public IHttpActionResult GetActiveListings()
    {
        try
        {
            var request = HttpContext.Current.Request;
            var settings = Properties.Settings.Default;
            using (var db = new Database(settings.DbType, settings.ConnectionString))
            {
                    var response = new Editor(db, "Products", "Id")
                        .Model<Product>()
                        .Process(request)
                        .Data();

                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                // Log this
                return BadRequest("error was found~!!");
            }
        }
    }

How can I overcome this issue? It is vital for me that some cols in the database table will be Nullable

Aucun commentaire:

Enregistrer un commentaire