Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON deserialization issue with POST request to Web API (using EF 5)
    primarykey
    data
    text
    <p>I have a data model generated using ADD.net DB model to generate .edmx file from a Azure SQL DB.</p> <p>The designer file containing code generated for .edmx file like like below - </p> <pre><code> public partial class DefectManagementSystemEntities : ObjectContext { #region Partial Methods partial void OnContextCreated(); #endregion #region ObjectSet Properties /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; public ObjectSet&lt;User&gt; Users { get { if ((_Users == null)) { _Users = base.CreateObjectSet&lt;User&gt;("Users"); } return _Users; } } private ObjectSet&lt;User&gt; _Users; /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; public ObjectSet&lt;WorkItem&gt; WorkItems { get { if ((_WorkItems == null)) { _WorkItems = base.CreateObjectSet&lt;WorkItem&gt;("WorkItems"); } return _WorkItems; } } private ObjectSet&lt;WorkItem&gt; _WorkItems; #endregion #region Entities /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmEntityTypeAttribute(NamespaceName="DefectManagementSystemModel", Name="User")] [Serializable()] [DataContractAttribute(IsReference=true)] public partial class User : EntityObject { #region Factory Method /// &lt;summary&gt; /// Create a new User object. /// &lt;/summary&gt; /// &lt;param name="id"&gt;Initial value of the ID property.&lt;/param&gt; /// &lt;param name="login_Id"&gt;Initial value of the Login_Id property.&lt;/param&gt; /// &lt;param name="password"&gt;Initial value of the Password property.&lt;/param&gt; /// &lt;param name="role"&gt;Initial value of the Role property.&lt;/param&gt; public static User CreateUser(global::System.Int32 id, global::System.String login_Id, global::System.String password, global::System.Int32 role) { User user = new User(); user.ID = id; user.Login_Id = login_Id; user.Password = password; user.Role = role; return user; } #endregion #region Simple Properties /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 ID { get { return _ID; } set { if (_ID != value) { OnIDChanging(value); ReportPropertyChanging("ID"); _ID = StructuralObject.SetValidValue(value, "ID"); ReportPropertyChanged("ID"); OnIDChanged(); } } } private global::System.Int32 _ID; partial void OnIDChanging(global::System.Int32 value); partial void OnIDChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String First_Name { get { return _First_Name; } set { OnFirst_NameChanging(value); ReportPropertyChanging("First_Name"); _First_Name = StructuralObject.SetValidValue(value, true, "First_Name"); ReportPropertyChanged("First_Name"); OnFirst_NameChanged(); } } private global::System.String _First_Name; partial void OnFirst_NameChanging(global::System.String value); partial void OnFirst_NameChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String Last_Name { get { return _Last_Name; } set { OnLast_NameChanging(value); ReportPropertyChanging("Last_Name"); _Last_Name = StructuralObject.SetValidValue(value, true, "Last_Name"); ReportPropertyChanged("Last_Name"); OnLast_NameChanged(); } } private global::System.String _Last_Name; partial void OnLast_NameChanging(global::System.String value); partial void OnLast_NameChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.String Login_Id { get { return _Login_Id; } set { OnLogin_IdChanging(value); ReportPropertyChanging("Login_Id"); _Login_Id = StructuralObject.SetValidValue(value, false, "Login_Id"); ReportPropertyChanged("Login_Id"); OnLogin_IdChanged(); } } private global::System.String _Login_Id; partial void OnLogin_IdChanging(global::System.String value); partial void OnLogin_IdChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.String Password { get { return _Password; } set { OnPasswordChanging(value); ReportPropertyChanging("Password"); _Password = StructuralObject.SetValidValue(value, false, "Password"); ReportPropertyChanged("Password"); OnPasswordChanged(); } } private global::System.String _Password; partial void OnPasswordChanging(global::System.String value); partial void OnPasswordChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 Role { get { return _Role; } set { OnRoleChanging(value); ReportPropertyChanging("Role"); _Role = StructuralObject.SetValidValue(value, "Role"); ReportPropertyChanged("Role"); OnRoleChanged(); } } private global::System.Int32 _Role; partial void OnRoleChanging(global::System.Int32 value); partial void OnRoleChanged(); #endregion } /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmEntityTypeAttribute(NamespaceName="DefectManagementSystemModel", Name="WorkItem")] [Serializable()] [DataContractAttribute(IsReference=true)] public partial class WorkItem : EntityObject { #region Factory Method /// &lt;summary&gt; /// Create a new WorkItem object. /// &lt;/summary&gt; /// &lt;param name="id"&gt;Initial value of the ID property.&lt;/param&gt; /// &lt;param name="type"&gt;Initial value of the Type property.&lt;/param&gt; /// &lt;param name="status"&gt;Initial value of the Status property.&lt;/param&gt; /// &lt;param name="title"&gt;Initial value of the Title property.&lt;/param&gt; /// &lt;param name="priority"&gt;Initial value of the Priority property.&lt;/param&gt; /// &lt;param name="severity"&gt;Initial value of the Severity property.&lt;/param&gt; /// &lt;param name="assignTo"&gt;Initial value of the AssignTo property.&lt;/param&gt; /// &lt;param name="openedBy"&gt;Initial value of the OpenedBy property.&lt;/param&gt; /// &lt;param name="areaPath"&gt;Initial value of the AreaPath property.&lt;/param&gt; public static WorkItem CreateWorkItem(global::System.Int32 id, global::System.Int32 type, global::System.Int32 status, global::System.String title, global::System.Int32 priority, global::System.Int32 severity, global::System.Int32 assignTo, global::System.Int32 openedBy, global::System.String areaPath) { WorkItem workItem = new WorkItem(); workItem.ID = id; workItem.Type = type; workItem.Status = status; workItem.Title = title; workItem.Priority = priority; workItem.Severity = severity; workItem.AssignTo = assignTo; workItem.OpenedBy = openedBy; workItem.AreaPath = areaPath; return workItem; } #endregion #region Simple Properties /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 ID { get { return _ID; } set { if (_ID != value) { OnIDChanging(value); ReportPropertyChanging("ID"); _ID = StructuralObject.SetValidValue(value, "ID"); ReportPropertyChanged("ID"); OnIDChanged(); } } } private global::System.Int32 _ID; partial void OnIDChanging(global::System.Int32 value); partial void OnIDChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 Type { get { return _Type; } set { OnTypeChanging(value); ReportPropertyChanging("Type"); _Type = StructuralObject.SetValidValue(value, "Type"); ReportPropertyChanged("Type"); OnTypeChanged(); } } private global::System.Int32 _Type; partial void OnTypeChanging(global::System.Int32 value); partial void OnTypeChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 Status { get { return _Status; } set { OnStatusChanging(value); ReportPropertyChanging("Status"); _Status = StructuralObject.SetValidValue(value, "Status"); ReportPropertyChanged("Status"); OnStatusChanged(); } } private global::System.Int32 _Status; partial void OnStatusChanging(global::System.Int32 value); partial void OnStatusChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.String Title { get { return _Title; } set { OnTitleChanging(value); ReportPropertyChanging("Title"); _Title = StructuralObject.SetValidValue(value, false, "Title"); ReportPropertyChanged("Title"); OnTitleChanged(); } } private global::System.String _Title; partial void OnTitleChanging(global::System.String value); partial void OnTitleChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String Description { get { return _Description; } set { OnDescriptionChanging(value); ReportPropertyChanging("Description"); _Description = StructuralObject.SetValidValue(value, true, "Description"); ReportPropertyChanged("Description"); OnDescriptionChanged(); } } private global::System.String _Description; partial void OnDescriptionChanging(global::System.String value); partial void OnDescriptionChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 Priority { get { return _Priority; } set { OnPriorityChanging(value); ReportPropertyChanging("Priority"); _Priority = StructuralObject.SetValidValue(value, "Priority"); ReportPropertyChanged("Priority"); OnPriorityChanged(); } } private global::System.Int32 _Priority; partial void OnPriorityChanging(global::System.Int32 value); partial void OnPriorityChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 Severity { get { return _Severity; } set { OnSeverityChanging(value); ReportPropertyChanging("Severity"); _Severity = StructuralObject.SetValidValue(value, "Severity"); ReportPropertyChanged("Severity"); OnSeverityChanged(); } } private global::System.Int32 _Severity; partial void OnSeverityChanging(global::System.Int32 value); partial void OnSeverityChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String Environment { get { return _Environment; } set { OnEnvironmentChanging(value); ReportPropertyChanging("Environment"); _Environment = StructuralObject.SetValidValue(value, true, "Environment"); ReportPropertyChanged("Environment"); OnEnvironmentChanged(); } } private global::System.String _Environment; partial void OnEnvironmentChanging(global::System.String value); partial void OnEnvironmentChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String OS { get { return _OS; } set { OnOSChanging(value); ReportPropertyChanging("OS"); _OS = StructuralObject.SetValidValue(value, true, "OS"); ReportPropertyChanged("OS"); OnOSChanged(); } } private global::System.String _OS; partial void OnOSChanging(global::System.String value); partial void OnOSChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String Browser { get { return _Browser; } set { OnBrowserChanging(value); ReportPropertyChanging("Browser"); _Browser = StructuralObject.SetValidValue(value, true, "Browser"); ReportPropertyChanged("Browser"); OnBrowserChanged(); } } private global::System.String _Browser; partial void OnBrowserChanging(global::System.String value); partial void OnBrowserChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable&lt;global::System.Int32&gt; Resolution { get { return _Resolution; } set { OnResolutionChanging(value); ReportPropertyChanging("Resolution"); _Resolution = StructuralObject.SetValidValue(value, "Resolution"); ReportPropertyChanged("Resolution"); OnResolutionChanged(); } } private Nullable&lt;global::System.Int32&gt; _Resolution; partial void OnResolutionChanging(Nullable&lt;global::System.Int32&gt; value); partial void OnResolutionChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable&lt;global::System.Int32&gt; Build { get { return _Build; } set { OnBuildChanging(value); ReportPropertyChanging("Build"); _Build = StructuralObject.SetValidValue(value, "Build"); ReportPropertyChanged("Build"); OnBuildChanged(); } } private Nullable&lt;global::System.Int32&gt; _Build; partial void OnBuildChanging(Nullable&lt;global::System.Int32&gt; value); partial void OnBuildChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 AssignTo { get { return _AssignTo; } set { OnAssignToChanging(value); ReportPropertyChanging("AssignTo"); _AssignTo = StructuralObject.SetValidValue(value, "AssignTo"); ReportPropertyChanged("AssignTo"); OnAssignToChanged(); } } private global::System.Int32 _AssignTo; partial void OnAssignToChanging(global::System.Int32 value); partial void OnAssignToChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 OpenedBy { get { return _OpenedBy; } set { OnOpenedByChanging(value); ReportPropertyChanging("OpenedBy"); _OpenedBy = StructuralObject.SetValidValue(value, "OpenedBy"); ReportPropertyChanged("OpenedBy"); OnOpenedByChanged(); } } private global::System.Int32 _OpenedBy; partial void OnOpenedByChanging(global::System.Int32 value); partial void OnOpenedByChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable&lt;global::System.Int32&gt; ActivatedBy { get { return _ActivatedBy; } set { OnActivatedByChanging(value); ReportPropertyChanging("ActivatedBy"); _ActivatedBy = StructuralObject.SetValidValue(value, "ActivatedBy"); ReportPropertyChanged("ActivatedBy"); OnActivatedByChanged(); } } private Nullable&lt;global::System.Int32&gt; _ActivatedBy; partial void OnActivatedByChanging(Nullable&lt;global::System.Int32&gt; value); partial void OnActivatedByChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable&lt;global::System.Int32&gt; ClosedBy { get { return _ClosedBy; } set { OnClosedByChanging(value); ReportPropertyChanging("ClosedBy"); _ClosedBy = StructuralObject.SetValidValue(value, "ClosedBy"); ReportPropertyChanged("ClosedBy"); OnClosedByChanged(); } } private Nullable&lt;global::System.Int32&gt; _ClosedBy; partial void OnClosedByChanging(Nullable&lt;global::System.Int32&gt; value); partial void OnClosedByChanged(); /// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [DataMemberAttribute()] public global::System.String AreaPath { get { return _AreaPath; } set { OnAreaPathChanging(value); ReportPropertyChanging("AreaPath"); _AreaPath = StructuralObject.SetValidValue(value, false, "AreaPath"); ReportPropertyChanged("AreaPath"); OnAreaPathChanged(); } } private global::System.String _AreaPath; partial void OnAreaPathChanging(global::System.String value); partial void OnAreaPathChanged(); #endregion } #endregion } </code></pre> <p>And a Controller method as </p> <pre><code> public class UserController : ApiController { DMSDataAccessLayer DBUser = new DMSDataAccessLayer(); // GET api/User/All [HttpGet] public IEnumerable&lt;UserDTO&gt; Get() { return DBUser.ReadAllUsersFromDMS(); } // POST api/User public HttpResponseMessage Post(User user) { try { //DBUser.InsertToDMS(user); } catch (Exception e) { Logger.ErrorLog(e.Message); throw e; } return Request.CreateResponse(HttpStatusCode.Created); } </code></pre> <p>The JSON Body i'm passing in POST request is - </p> <pre><code> {"User": [{"ID":1,"First_Name":"Vaibhav","Last_Name":"N","Login_Id":"manishn_007@hotmail.com", "Password":"test123","Role":0}]} </code></pre> <p>Problem:</p> <ol> <li>Though i can send the Post request to Web API, <em>user</em> object gets populated with properties having values set as <em>null</em>.</li> </ol> <p>To me, the problem seems to be with JSON serialization. I try Bing the problem and found the JSON serialization which come inbuild with Web API is crappy and need to custom define JSON.NET as default serializer. unfortunately, This didn't work for me.</p> <p>Is there anything i'm possibly missing?</p> <p>Oh Yes, The Post request i'm sending through fiddler looks like </p> <pre><code> Connection: keep-alive Content-Length: 76 X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 Accept: application/json, text/javascript, */*; q=0.01 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload