nopcommerce 1.9에 문제가있어서 정말 도움이 필요합니다.IEntityChangeTracker의 여러 인스턴스에서 엔티티 개체를 참조 할 수 없습니다.
내가하고있는 작업은 기존 기능에 제품 가져 오기 도구를 추가하는 것입니다.
iisreset 다음에 처음 실행하면 가져 오기 프로그램이 정상적으로 실행됩니다. 그러나 두 번째 이후에는 더 이상의 인스턴스가 위의 오류를 생성합니다. 이것은 다음 코드 IoC.Resolve(). UpdateProduct (product)를 실행할 때 끊임없이 발생하는 것 같습니다.
/// <summary>
/// Updates the product
/// </summary>
/// <param name="product">Product</param>
public void UpdateProduct(Product product)
{
if (product == null)
throw new ArgumentNullException("product");
product.Name = CommonHelper.EnsureNotNull(product.Name);
product.Name = CommonHelper.EnsureMaximumLength(product.Name, 400);
product.ShortDescription = CommonHelper.EnsureNotNull(product.ShortDescription);
product.FullDescription = CommonHelper.EnsureNotNull(product.FullDescription);
product.AdminComment = CommonHelper.EnsureNotNull(product.AdminComment);
product.MetaKeywords = CommonHelper.EnsureNotNull(product.MetaKeywords);
product.MetaKeywords = CommonHelper.EnsureMaximumLength(product.MetaKeywords, 400);
product.MetaDescription = CommonHelper.EnsureNotNull(product.MetaDescription);
product.MetaDescription = CommonHelper.EnsureMaximumLength(product.MetaDescription, 4000);
product.MetaTitle = CommonHelper.EnsureNotNull(product.MetaTitle);
product.MetaTitle = CommonHelper.EnsureMaximumLength(product.MetaTitle, 400);
product.SEName = CommonHelper.EnsureNotNull(product.SEName);
product.SEName = CommonHelper.EnsureMaximumLength(product.SEName, 100);
if (!_context.IsAttached(product))
_context.Products.Attach(product);
_context.SaveChanges();
if (this.CacheEnabled)
{
_cacheManager.RemoveByPattern(PRODUCTS_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTVARIANTS_PATTERN_KEY);
_cacheManager.RemoveByPattern(TIERPRICES_PATTERN_KEY);
_cacheManager.RemoveByPattern(CUSTOMERROLEPRICES_PATTERN_KEY);
}
//raise event
EventContext.Current.OnProductUpdated(null,
new ProductEventArgs() { Product = product });
}
내가 기술 (ObjectContexts) 이러한 유형의 매우 많은 경험을 가지고 있지 않기 때문에 완벽한 솔루션을 제공 할 수 있다면, 그것은 매우 감사하겠습니다 :이 호출하는 코드는 다음과 같습니다. 인터넷에서이 오류에 대한 예를 많이 보았지만 나에게 맞는 솔루션을 찾지 못했습니다. 필자가 읽은 바로는 분명히 제품이 두 개의 다른 ObjectContext에 연결된다는 것입니다. 나는 이것이 여기서 일어나는 일이라고 추측하지만, 어디서/왜 있는지를 알아내는 기술에 대해 충분히 알지 못합니다. SaveChanges 후에 분리하려고 했으므로 다음 번에 동일한 객체를 다시 연결하지 않았지만 예상대로 해결되지 않았습니다.
많은 감사, Adrian.
디버깅 할 때 Attach (product) 문을 실행합니까? –
그건 그게 오류 라인이야. – ajbrun