c# - dbContext.SaveChanges() not saving and not outputting an error -


I am trying to update the user-object in my MVC-project, but it seems to save new values I do not have the input.

Is there a place where I am doing something wrong?

This is the way I am saving, I know that I db Save Changes (); By running my debug. Type () .

  Public Bull Edit User (String Email, User Inn User) {var db = new PastaContext (); Try {User editUser = db.Users.Find (email); EditUser.Firstname = innUser.Firstname; Debug.WriteLine (innUser.Firstname); Debug.WriteLine (editUser.Firstname); EditUser.Surname = innUser.Surname; EditUser.Address = innUser.Address; EditUser.Phonenr = innUser.Ponenr; Var newUser = new dbUser (); Byte [] passwordDb = createHash (innUser.Password); NewUser.Password = passwordDb; NewUser.Email = Email; If (editUser.Postcode! = InnUser.Postcode) {Debug.WriteLine ("Inside in Postcode"); // changed the postcode. First check that the new postcob is already present in the city. City = Existing = db.Cities.Find (innUser.Postcode); If (existing CT == empty) {Debug.WriteLine ("Inside in Non Prospecting Postcode"); // PostState integration ikke, management leases in var newCity = new City () {Postcode = innUser.Postcode, Cityname = innUser.city.Cityname}; Db.Cities.Add (Newcity); } Another {// city with new postcode already exists, only the user editing user's PIN code is changing. Post code = innUser.Postcode; Debug. Wrightite ("in the postcode in the past"); }}; Debug.lightline ("before saving"); Db.SaveChanges (); Debug.lightline ("return true"); Back true; } Hold {Debug.WriteLine ("return"); return false; }}   

exception catching output:

  System.Data.Entity.Validation.DbEntityValidationException: failed validation for one or more entities. For more details 'EntityValidationErrors' Oblig1 on System.Data.Entity.DbContext.SaveChanges () on System.Data.Entity.Internal.LazyInternalContext.SaveChanges () See Property System.Data.Entity.Internal.InternalContext.SaveChanges () on .DBUser.editUser (string email, user-inn user) c: \ users \ XXX \ XXX \ XXX \ XXX \ DBUser.cs: row 55   

errors output: < / P>

  A type 'system.data.tt.validation' was the first chance in the EntityFramework.dll in the state of the "City" type "Added" in the following verification Errors: - Property: "postcode" Error: "postcode should be added to the" type of unit "User_546F9926F8DC53E2EF66BA48BE43lDFlB26DEBEFA54B0597E60AEBl839DD022C" "state modified" following validation errors: - Property: "City", error: "City area required .   

Model I am experimenting with three tables:

  public class user {[required (error message = "first name added Should ")] public string Randomname {Received; Set; } [Required (error message = "surname should be added")] Public string aliases {get; Set; } [Required (error message = "Address should be added")] Public string address {get; Set; } Public string postcode {get; Set; } [Key] [Required (error message = "must be e-mail")] [datatype (datatype. Email address)] [email address] public string email {get; Set; } [Required (Error Message = "Phoneer must be added")] {Receive Public String Foneer; Set; } [Required (error message = "password should be added")] Public string password {get; Set; } [Required] Public Virtual City City {Receive; Set; } Public Virtual List & lt; Order & gt; Order Received; Set; }} Public class dbUser {[Key] public string email {get; Set; } Receive the public byte [] password; Set; }} Public square city {[key] [required (error message = "postcode should be added")] public string postcode {get; Set; } [Required (error message = "City should be added")] Public string cityname {get; Set; }}    

When you create your new city object, you do so: / P>

  var newCity = new city () {Postcode = innUser.Postcode, Cityname = innUser.city.Cityname};   

Instead you need to set up postcode using the property like City.Postcode :

  var newCity = new City ( ) {Postcode = innUser.city.Postcode, Cityname = innUser.city.Cityname};    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -