0
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="Id,Reciever_Area,Parcel_Type,Delivery_Type,Parcel_Weight,Final_Cost")] quotation quotation)
{
    if (ModelState.IsValid)
    {
        db.quotations.Add(quotation);    <-- this isn't working
        db.SaveChanges();
        return RedirectToAction("Index", "Home");
    }

    return View(quotation);
}

This is the error message I get:

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: The entity type quotation is not part of the model for the current context.

1
  • It sounds like your instance of DbContext is not aware of the Quotation type. I would need to know information about how you are generating your DbContext (database first, code first) class before providing additional detail. Commented Apr 22, 2016 at 19:37

1 Answer 1

1

Since the quotation object is not created in the current dbContext thus you've to attach it before adding it.

 db.quotations.Attach(quotation);
 db.quotations.Add(quotation);
Sign up to request clarification or add additional context in comments.

1 Comment

The line of code db.quotations.Add(quotation); attaches the entity (in this case, quotation) to the DbContext and sets its state to Added. That said, the first line of code is not needed.

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.