Validate data input into the navigation properties RRS feed

  • Question

  • I would like to know how to validate data in navigation properties.

    Example:Product.Ingredients.Add(new Ingredient())

    How can I verify if all ingredients is there at database before using SaveChanges()?

    Even if I use a repository, a developer can set a new Ingredient using Product.Ingredient, so repository is not my anwser.

    Can someone help me?

    Monday, May 28, 2012 2:22 PM

All replies

  • You could expose a SaveChanges() method in your repository that hides the context.SaveChanges() method and can do additional checks before calling context.SaveChanges().
    Monday, May 28, 2012 11:43 PM
  • But I use UnitOfWork to save my changes, not directly from repository.

    Tuesday, May 29, 2012 11:52 AM