title: Getting 500 - Internal Server Error with Ajax Jquery Method for an Entity Framework
body: <p>I did <a href="https://www.codeproject.com/Articles/692793/Introduction-to-Knockout-js-and-CRUD-Operations-in" rel="nofollow noreferrer">this tutorial</a> to get warm with SQL-Databases and the Entity-Frameworks and Knockout.js. </p>
  
  <p>I thought I could arrange the code to get connected to my own database.</p>
  
  <p>In order to develop a MVVM based webapplication this is the ViewModel:<br>
  [ViewModel with observation calls in Javascript by Knockout.js]</p>
  
  <pre class="lang-js prettyprint-override"><code>    function Device(data) {
          this.Date = ko.observable(data.Date);
          this.Value = ko.observable(data.Value);
          this.ObjectID = ko.observable(data.ObjectID);
          this.TypeID = ko.observable(data.TypeID);
      }
  
  
      function DeviceViewModel() {
          var self = this;
          self.Devices = ko.observableArray([]);
          self.Date = ko.observable();
          self.Value = ko.observable();
          self.ObjectID = ko.observable();
          self.TypeID = ko.observable();
  
         $.ajax({
              type: "POST",
              url: 'LearnKO.aspx/FetchDevices',
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (results) {
                  var devices = $.map(results.d, function (item) {
                      return new Device(item)
  
                  });
                  self.Devices(devices);
              },
              error: function (err) {
                  alert(err.status + " - " + err.statusText);
              }
          })
      }
  $(document).ready(function () {
      ko.applyBindings(new StudentViewModel());
  });
  </code></pre>
  
  <p>The ajax method should call a webMethod in an .aspx.cs data:</p>
  
  <pre><code>[WebMethod]
  
  public static DEVICE_VALUES[] FetchDevices()
  {   
      DiagmaResultsEntities dbEntitiesDiagma = new 
          DiagmaResultsEntities();
      var dataDiagma = (from item in dbEntitiesDiagma.DEVICE_VALUES
                        orderby item.Value
                        select item).Take(12);
      return dataDiagma.ToArray();
  }
  </code></pre>
  
  <p>And this is my SQL-Database:
  <a href="https://i.stack.imgur.com/DNLc4.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>I want to get "date","value","ObjectID", and "typeID" out of that EF. But im getting this error and can't find myself a possible solution with google.</p>