public class User { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } public virtual Organization Organization { get; set; } } public class Organization { public int Id { get; set; } public string Name { get; set; } public string EmailAddress { get; set; } public string Password { get; set; } public override bool Equals(object obj) { Organization that = obj as Organization; if (that != null) { return (this.Id == that.Id); } return base.Equals(obj); } }
Cannot insert explicit value for identity column in table 'Organizations' when IDENTITY_INSERT is set to OFF.
[HttpPost] public async Task<IActionResult> Post([FromBody]User p_User) { try { using (var dataContext = new AspCoreContext(AspCoreContext.BuildOptions())) { dataContext.Users.Add(p_User); await dataContext.SaveChangesAsync(); return Ok(p_User); } } catch (Exception ex) { const string msg = "Unable to insert user"; Globals.ErrorLogger(ex, msg); return StatusCode((int)HttpStatusCode.InternalServerError, msg); } }
{ "name": "Qadeer", "password": "123456", "token": null, "organization": {"Id": "1"} }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)