Applied WPF 4 In Context – p4

So I’m still working on getting through Chapter 6 – almost there. Right now I made it to Page 151, the start of the Repository pattern.  If  you are struggling with Applied WPF 4 in Context by Raffaele Garofalo, below I have a list of things that might you get through Chapter 6.

  1. Ignore the top of page 140 where it says run the test. It won’t work because IUnitOfWork is not fully implemented yet.
  2. In IUnitOfWork, change void BeginTransaction(); to be void StartTransaction(); Raffaele switches to using StartTransaction at the top of  page 141 but he doesn’t update the interface.
  3. In IUnitOfWork, change the method definition by adding the where T: class like so:
  4. void MarkDirty<T>(T entity) where T : class;
    void MarkNew<T>(T entity) where T : class;
    void MarkDeleted<T>(T entity) where T : class;
  5. On pages 143-150, Raffaele discusses the Add, Update and Remove Objects, the trouble is that he skips the MarkDeleted implementation. Look at page 145, he jumps straight to the test method. As a result I created my own:
  6. public void MarkDeleted<T>(T entity) where T : class
    {
         session.DeleteObject(entity);
    }

Screen shot of VS 2010:

Chapter 6 - Test Complete

Chapter 6 - Test Complete

 

6 thoughts on “Applied WPF 4 In Context – p4

  1. Both books from Raffaele Garofalo that I bought had incomplete code(Applied WPF in context, Build enterprise application with WPF and MVVM). But for me the full code is an essential part of the book. That’s why I’m going to buy any more books by Garofalo.

  2. Hello, thanks for the status updates, as I’m still on Chap5. Maybe you can help. I’ve add

    public Window ShowLoginWindow()
    {
    var window = Container.Resolve();
    window.ShowDialog();
    return window;
    }

    to the implementation of NavigationService but since I have no reference to the WPF app, it does not know what LoginView is. Would happen to know what I’m doing wrong? Or do I need to reference the main app in the ServiceLayer? thanks for all the other tips

    • Harold,
      here’s mine right now….

      public Window ShowLoginWindow()
      {
      var window = Container.Resolve();
      window.ShowDialog();
      return window;
      }
      I believe it is identical to page 99. I also added a reference to…

      using APRESS.TimeTracker.Views;

      in both the App.xaml.cs and the NavigationService.cs files.

      Raffaele loosely identified the need for it in the starting comments of listing 5-8 which is also on page 99.

      Also, if you haven’t added it yet, you need to add a method to INavigationService – see the third line of page 100 in the book.
      Here’s mine….

      public interface INavigationService
      {
      bool ConfirmClose();

      Window ShowMainWindow();
      Window ShowLoginWindow();
      }

      Hope that helps. I’m still on Chapter 7, but I was vacation so I’ll get back to this week.

  3. Thanks for the help, I had the services, in the service layer, not noting the namespace on page 82. This is why I had so much trouble and your reply helped me get on track. Now I can move on to Chap 6.

    Raffaele is working on getting the source published.

  4. I’m quite stuck in chapter 6 at the “CanDeleteAnExistingObject” it keeps throwing this exception:”Assert.Fail failed. System.InvalidOperationException: The object cannot be deleted because it was not found in the ObjectStateManager.
    at System.Data.Objects.ObjectContext.DeleteObject(Object entity, EntitySet expectedEntitySet)
    at System.Data.Objects.ObjectContext.DeleteObject(Object entity)
    at DataLayer.UnitOfWork.MarkDeleted[T](T entity) in C:\DC\Programming\Tutorials\WPF\TimeTrack\Apress.TimeTracker\Apress.TimeTracker\Application\DataLayer\UnitOfWork.cs:line 56
    at Test.Fixtures.UnitOfWorkFixture.CanDeleteAnExistingObject() in C:\DC\Programming\Tutorials\WPF\TimeTrack\Apress.TimeTracker\Test\Fixtures\UnitOfWorkFixture.cs:line 138″
    Please help

    • I ran into the same problem …I think its due to Repeating BeginTransaction call as it creates a new objectcontext and our added role is not in the new context. I modified it a little bit :
      uow.BeginTrasaction();
      var expectedRole = uow.Session.CreateObjectSet().FirstOrDefault();
      Assert.IsNotNull(expectedRole);
      //delete the object

      uow.MarkDeleted(expectedRole);
      Assert.IsTrue(expectedRole.EntityState == System.Data.EntityState.Deleted);
      uow.CommitTransaction();
      //verify the object dosen’t exist
      var finalExpectedRole = uow.Session.CreateObjectSet()
      .FirstOrDefault();
      Assert.AreNotSame(finalExpectedRole,expectedRole);

      Please let me know if anyone has found any other solution for it.

Leave a Reply

Your email address will not be published. Required fields are marked *