I have the following method:
public void InsertOrUpdate(AmazonProduct amazonProduct)
{
var product = context.AmazonProducts
.Include(x => x.AmazonLowestOfferListings)
.Include(x => x.AmazonMyPrices)
.Include(x => x.AmazonProductCompetitivePrices)
.FirstOrDefault(p => p.ASIN == amazonProduct.ASIN);
if (product == null)
{
// New entity
context.AmazonProducts.Add(amazonProduct);
}
else
{
foreach (var lineItem in amazonProduct.AmazonLowestOfferListings)
{
context.AmazonLowestOfferListings.Add(lineItem);
}
context.Entry(product).CurrentValues.SetValues(amazonProduct);
}
}
But on the line,
foreach (var lineItem in amazonProduct.AmazonLowestOfferListings)
it gives me the error:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
I dont get it.. I havent even added it to the context yet, and it still gives me this error? Any one any idea?
thanks Neil