Problem with SaveChangesAsync

Oct 2, 2015 at 3:05 PM
Edited Oct 2, 2015 at 3:05 PM
I am having a problem getting the repository InsertOrUpdateGraph() method to work with SaveChangesAsync. Here is my test application:
public class User {
  public int UserId { get; set; }
  public string Email { get; set; }

  public virtual UserDetails Details { get; set; }

public class UserDetails {
  public int UserId { get; set; }
  public string Name { get; set; }
  public int Age { get; set; }
I then map them as follows:
public class UserMap : EntityTypeConfiguration<User>
  public UserMap() {

    HasKey(u => u.UserId);

    Property(u => u.UserId)

   Property(u => u.Email)

    HasRequired(u => u.Details)

public class UserDetailsMap : EntityTypeConfiguration<UserDetails>
  public UserDetailsMap() {
    HasKey(d => d.UserId);
    Property(d => d.UserId)

   Property(u => u.Name)

   Property(u => u.Age)
If I then try and insert a new User...
var user = new User
        Email = "booha@somedomain",
    Details = new UserDetails
            Name = "Boo Ha",
            Age = 99,
        ObjectState = ObjectState.Added
    ObjectState = ObjectState.Added

await _unitOfWork.SaveChangesAsync();
I get the following exception...
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_app_UserDetails_app_User". The conflict occurred in database "TestDb", table "dbo.app_User", column 'UserId'.
The statement has been terminated.
But if I change the call to non-asynchronous, it works correctly. Interestingly if I change the lines
await _unitOfWork.SaveChangesAsync();
using (var ctx = new AppDataContext()) {
The insert runs without exception too.

Am I doing something wrong? Has anyone else experienced this problem?

Oct 2, 2015 at 3:24 PM
I have added a simple Windows console application to GitGub that seems to demonstrate the problem - see
Oct 12, 2015 at 12:51 AM
Edited Oct 12, 2015 at 12:51 AM
I need your help if you please
my question is:
Did you face a problem with navigation properties(they don't load/always empty) when you are using URF v3.3.5?
I need to know if the problem is from my side or it's from the URF v3.3.5.
Thank you for your time.
Oct 12, 2015 at 7:48 AM
No, I did not have a problem with loading navigation properties. As I understand it you have two basic options (there might be other options so please check):
  1. Use the appropriate .Include() statement(s) when building the query if you are referencing the default URF data context, or...
  2. Re-enable LazyLoading in your DataContext constructor:
        public MyAppDataContext()
            : base("Name=MyAppConnectionString")
            // Default URF configuration
            // Configuration.LazyLoadingEnabled = false;
            // Configuration.ProxyCreationEnabled = false;

            // Re-Enable
            Configuration.LazyLoadingEnabled = true;
            Configuration.ProxyCreationEnabled = true;
Hope that helps.
Oct 14, 2015 at 1:53 AM
Thank you a lot :)