0

In here I add some data to database using EF code.When i add using one context it's working.But I need to update another table(another context) using ProductId(productId avaialble in iOdr object.

Here is my code

public int AddorUpdateSalesOrder(ref InvoiceHD iOdr)
{
    try
    {
        if (iOdr.InvoiceId != null)
        {
           //context.Entry(iOdr).State = EntityState.Modified;
           context.InvoiceHDs.Add(iOdr);
           //Here I need to update Product context 
           //using ProductId(it's available in iOdr).
           //If ProductId is 1 then I need to 
           //update product tables ProductQuantity coloumn with new value
        }
        else
        {
            context.InvoiceHDs.Add(iOdr);
        }
    }
    catch (Exception ex)
    {
        string msg = ex.Message;
    }
    return context.SaveChanges();
}

I have no idea how to do second context.could you please someone give me help for this. thanks

1 Answer 1

1

If I am reading this correctly then you just need to create a new instance of your other context, get back the record you need to update, update that record and SaveChanges on that context.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.