Durable Entity Framework Context - Best Practices for Avoiding Data Integrity Issues

As a very rudimentary scenario, take two operations:

UserManager.UpdateFirstName(int userId, string firstName)
{
    User user = userRepository.GetById(userId);
    user.FirstName = firstName;
    userRepository.SaveChanges();
}

InventoryManager.InsertOrder(Order newOrder)
{
    orderRepository.Add(newOrder);
    orderRepository.SaveChanges();
}

I only used EF in web projects and relied heavily on the nature of the stateless network. With each request, I get a fresh copy of the context entered into the facade objects of the business layer (services, managers, whatever you want to name them), all business managers who use the same instance of the EF context. I am currently working on a WPF project, and I am implementing business managers and subsequently the repositories that they use directly in Model View.

, , UpdateFirstName(). , SaveChanges() - . InsertOrder().

, №2 ( HTTP-) , # 1. . , . , SaveChanges() (, db ), , SaveChanges(), , . , , .

, , , , , , ( WPF, ).

, , ?

+5
3

, .

, , -, ORM, - , , . - , , Unit of Work. - , , , .

, , ( "" ). throwaway ( , , , "" ). , , ( ). EF , , , .

, ORM - - . . , . , . , EF , " "...

+3

WPF, WCF CRUD, 'UpdateFirstName() ' InsertOrder(). ObjectContext, - .

ObjectContext, . Nothings ObjectContext . Theres ObjectContext, .

, ObjectContext , , - TransactionScope. ,

        using (TransactionScope scope = new TransactionScope())
        {
            UserManager.UpdateFirstName(userid,firstName);
            InventoryManager.InsertOrder(newOrder);

            scope.Complete();
        }
+2

( ). - / . , ok/undo/cancel.

0

All Articles