yash patel

yash patel

  • NA
  • 274
  • 19.3k

Here i am getting an exception

Sep 26 2020 5:20 AM
The 1st table i.e. user table the data is saving but in the second table user i.e. user address it is not the following exception is coming
 
can anyone tell how to overcome this exception
 
Exception thrown: 'System.Data.Entity.Infrastructure.DbUpdateException' in EntityFramework.dll
Additional information: An error occurred while updating the entries. See the inner exception for details.
 
In addition to this i have 2 tables user and user address
 
USER = user id(primary key)
name
email
password
 
ADDRESS=addressid (primary key)
address
city
state
 
user id (foreign key from user table with primary key user id)
 
identity specification for both the primary keys is on.
  1. public CustomBO AddUser( UserBO objUserBO )  
  2. {  
  3. CustomBO objCustomBO = new CustomBO();  
  4. User objUser = new User();  
  5. {  
  6. objUser.UserEmail = objUserBO.UserEmail;  
  7. objUser.FullName = objUserBO.FullName;  
  8. objUser.Password = objUserBO.Password;  
  9. };  
  10. objnsrouteEntities.Users.Add(objUser);  
  11. objnsrouteEntities.SaveChanges();  
  12. return objCustomBO;  
  13. }  
  14. public CustomBO AddUserAddress( UserBO objUserBO )  
  15. {  
  16. CustomBO objCustomBO = new CustomBO();  
  17. UserAddress objUserAddress = new UserAddress();  
  18. {  
  19. objUserAddress.CompleteAddress = objUserBO.CompleteAddress;  
  20. objUserAddress.City = objUserBO.City;  
  21. objUserAddress.State = objUserBO.State;  
  22. }  
  23. //objUserAddress.UserId = objUserBO.UserId;  
  24. objnsrouteEntities.UserAddresses.Add(objUserAddress);  
  25. objnsrouteEntities.SaveChanges();  
  26. return objCustomBO;  
  27. }  

Answers (1)