title: How to retrieve new ID in EF Core using UoW pattern
body: <p>I'm having trouble retrieving the ID of newly added object in EF Core using the UoW pattern. I have this service:</p>
  
  <pre><code>public class OrderService : IOrderService
  {
      private IUnitOfWork _uow;
      private IOrderRepository _orderRepository;
      private IPaymentRepository _paymentRepository;
  
      public OrderService(IUnitOfWork uow,
          IOrderRepository orderRepository,
          IPaymentRepository paymentRepository)
      {
          _uow = uow;
          _orderRepository = orderRepository;
          _paymentRepository = paymentRepository;
      }
  
      public int CreateOrder(Logic.Order order)
      {
          var id = _orderRepository.CreateOrder(order);
  
          var payment = new Data.Payment();
          payment.OrderId = id;  // at this point, this is -2147353458 something
          _paymentRepository.CreatePayment(payment);
  
          // committed at this point but I can't get id unless I re-query
          _uow.Commit();
  
          // this is still -2147353458
          return id;
      }
  }
  </code></pre>
  
  <p>So CreateOrder just adds a new order and then the newly generated ID is returned and used by the Payment object in CreatePayment. The problem with this since after adding, it is not committed yet so EF Core generates a temp id (something like -2147483324) so this is what I get. I then pass this to payment but this part is ok since I think EF is tracking it. The problem is what I return to the UI. </p>
  
  <p>The service is called by the UI and after comitting, I can't get the ID. That's been my problem for hours now.</p>