2012-08-08 77 views
0

我目前有一個非常惱人的問題,從實體框架更新NopCommerce數據庫。NopCommerce/Entity Framework:產品遷移錯誤表

背景:

我寫了一個小工具,以一種過時的電子商務應用程序遷移到nopCommerce。

出現錯誤:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. 
The statement has been terminated. 

我做了什麼可以嘗試解決它

在過去,這種錯誤上來,當我有,這是未初始化的一個DateTime屬性(年0001)..但在這種情況下,這不是問題。我查看並確保所有的DateTime屬性都被設置。由於這沒有奏效,我也嘗試使db列datetime2(7),但沒有運氣。最後我把它設置爲NULLABLE,但它仍然給我同樣的錯誤。所以,這裏顯然還有其他一些事情發生,EF正在拋出一些無益的錯誤。我想知道是否在表上試圖創建一個條目或產生變量表的表或其他日期時間錯誤來自哪個表中的插入觸發器(或任何觸發器),但那不是案子。

的代碼:

foreach (var piloProduct in piloProducts) 
{ 
    var product = new Models.Nop.Product 
    { 
     Name = piloProduct.Name, 
     ShortDescription = piloProduct.ShortDescription, 
     FullDescription = piloProduct.FullDescription, 
     ProductTemplateId = 1, 
     ShowOnHomePage = false, 
     MetaKeywords = piloProduct.MetaKeywords, 
     MetaDescription = piloProduct.MetaDescription, 
     MetaTitle = piloProduct.MetaTitle, 
     SeName = piloProduct.SeName, 
     AllowCustomerReviews = false, 
     ApprovedRatingSum = 0, 
     NotApprovedRatingSum = 0, 
     ApprovedTotalReviews = 0, 
     NotApprovedTotalReviews = 0, 
     Published = true, 
     Deleted = false, 
     CreatedOnUtc = DateTime.UtcNow, 
     UpdatedOnUtc = DateTime.UtcNow 
    }; 
    nopDb.Products.AddObject(product); 
} 
nopDb.SaveChanges(); 

我在這一個完全喪失,如上面的代碼是非常簡單明瞭。任何幫助非常感謝。

UPDATE

我一直在使用LINQ到SQL類,而不是實體框架EDMX剛剛試過,但有完全相同的問題。奇怪的是,我直接從SQL Management Studio在表上運行了一個「INSERT INTO」語句,但它工作正常..去圖...有什麼辦法可以準確地看到EF或者生成了什麼「INSERT」語句LINQ到SQL?

而這裏的馬克Oreta要求EDMX生成的模型:

[EdmEntityTypeAttribute(NamespaceName="eSalesModel", Name="Product")] 
[Serializable()] 
[DataContractAttribute(IsReference=true)] 
public partial class Product : EntityObject 
{ 
    public static Product CreateProduct(global::System.Int32 id, global::System.String name, global::System.Int32 productTemplateId, global::System.Boolean showOnHomePage, global::System.Boolean allowCustomerReviews, global::System.Int32 approvedRatingSum, global::System.Int32 notApprovedRatingSum, global::System.Int32 approvedTotalReviews, global::System.Int32 notApprovedTotalReviews, global::System.Boolean published, global::System.Boolean deleted) 
    { 
     Product product = new Product(); 
     product.Id = id; 
     product.Name = name; 
     product.ProductTemplateId = productTemplateId; 
     product.ShowOnHomePage = showOnHomePage; 
     product.AllowCustomerReviews = allowCustomerReviews; 
     product.ApprovedRatingSum = approvedRatingSum; 
     product.NotApprovedRatingSum = notApprovedRatingSum; 
     product.ApprovedTotalReviews = approvedTotalReviews; 
     product.NotApprovedTotalReviews = notApprovedTotalReviews; 
     product.Published = published; 
     product.Deleted = deleted; 
     return product; 
    } 
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Int32 Id 
{ 
    get 
    { 
     return _Id; 
    } 
    set 
    { 
     if (_Id != value) 
     { 
      OnIdChanging(value); 
      ReportPropertyChanging("Id"); 
      _Id = StructuralObject.SetValidValue(value); 
      ReportPropertyChanged("Id"); 
      OnIdChanged(); 
     } 
    } 
} 
private global::System.Int32 _Id; 
partial void OnIdChanging(global::System.Int32 value); 
partial void OnIdChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public Nullable<global::System.Int32> PiloId 
{ 
    get 
    { 
     return _PiloId; 
    } 
    set 
    { 
     OnPiloIdChanging(value); 
     ReportPropertyChanging("PiloId"); 
     _PiloId = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("PiloId"); 
     OnPiloIdChanged(); 
    } 
} 
private Nullable<global::System.Int32> _PiloId; 
partial void OnPiloIdChanging(Nullable<global::System.Int32> value); 
partial void OnPiloIdChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.String Name 
{ 
    get 
    { 
     return _Name; 
    } 
    set 
    { 
     OnNameChanging(value); 
     ReportPropertyChanging("Name"); 
     _Name = StructuralObject.SetValidValue(value, false); 
     ReportPropertyChanged("Name"); 
     OnNameChanged(); 
    } 
} 
private global::System.String _Name; 
partial void OnNameChanging(global::System.String value); 
partial void OnNameChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String ShortDescription 
{ 
    get 
    { 
     return _ShortDescription; 
    } 
    set 
    { 
     OnShortDescriptionChanging(value); 
     ReportPropertyChanging("ShortDescription"); 
     _ShortDescription = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("ShortDescription"); 
     OnShortDescriptionChanged(); 
    } 
} 
private global::System.String _ShortDescription; 
partial void OnShortDescriptionChanging(global::System.String value); 
partial void OnShortDescriptionChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String FullDescription 
{ 
    get 
    { 
     return _FullDescription; 
    } 
    set 
    { 
     OnFullDescriptionChanging(value); 
     ReportPropertyChanging("FullDescription"); 
     _FullDescription = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("FullDescription"); 
     OnFullDescriptionChanged(); 
    } 
} 
private global::System.String _FullDescription; 
partial void OnFullDescriptionChanging(global::System.String value); 
partial void OnFullDescriptionChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String AdminComment 
{ 
    get 
    { 
     return _AdminComment; 
    } 
    set 
    { 
     OnAdminCommentChanging(value); 
     ReportPropertyChanging("AdminComment"); 
     _AdminComment = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("AdminComment"); 
     OnAdminCommentChanged(); 
    } 
} 
private global::System.String _AdminComment; 
partial void OnAdminCommentChanging(global::System.String value); 
partial void OnAdminCommentChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Int32 ProductTemplateId 
{ 
    get 
    { 
     return _ProductTemplateId; 
    } 
    set 
    { 
     OnProductTemplateIdChanging(value); 
     ReportPropertyChanging("ProductTemplateId"); 
     _ProductTemplateId = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("ProductTemplateId"); 
     OnProductTemplateIdChanged(); 
    } 
} 
private global::System.Int32 _ProductTemplateId; 
partial void OnProductTemplateIdChanging(global::System.Int32 value); 
partial void OnProductTemplateIdChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Boolean ShowOnHomePage 
{ 
    get 
    { 
     return _ShowOnHomePage; 
    } 
    set 
    { 
     OnShowOnHomePageChanging(value); 
     ReportPropertyChanging("ShowOnHomePage"); 
     _ShowOnHomePage = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("ShowOnHomePage"); 
     OnShowOnHomePageChanged(); 
    } 
} 
private global::System.Boolean _ShowOnHomePage; 
partial void OnShowOnHomePageChanging(global::System.Boolean value); 
partial void OnShowOnHomePageChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String MetaKeywords 
{ 
    get 
    { 
     return _MetaKeywords; 
    } 
    set 
    { 
     OnMetaKeywordsChanging(value); 
     ReportPropertyChanging("MetaKeywords"); 
     _MetaKeywords = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("MetaKeywords"); 
     OnMetaKeywordsChanged(); 
    } 
} 
private global::System.String _MetaKeywords; 
partial void OnMetaKeywordsChanging(global::System.String value); 
partial void OnMetaKeywordsChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String MetaDescription 
{ 
    get 
    { 
     return _MetaDescription; 
    } 
    set 
    { 
     OnMetaDescriptionChanging(value); 
     ReportPropertyChanging("MetaDescription"); 
     _MetaDescription = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("MetaDescription"); 
     OnMetaDescriptionChanged(); 
    } 
} 
private global::System.String _MetaDescription; 
partial void OnMetaDescriptionChanging(global::System.String value); 
partial void OnMetaDescriptionChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String MetaTitle 
{ 
    get 
    { 
     return _MetaTitle; 
    } 
    set 
    { 
     OnMetaTitleChanging(value); 
     ReportPropertyChanging("MetaTitle"); 
     _MetaTitle = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("MetaTitle"); 
     OnMetaTitleChanged(); 
    } 
} 
private global::System.String _MetaTitle; 
partial void OnMetaTitleChanging(global::System.String value); 
partial void OnMetaTitleChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public global::System.String SeName 
{ 
    get 
    { 
     return _SeName; 
    } 
    set 
    { 
     OnSeNameChanging(value); 
     ReportPropertyChanging("SeName"); 
     _SeName = StructuralObject.SetValidValue(value, true); 
     ReportPropertyChanged("SeName"); 
     OnSeNameChanged(); 
    } 
} 
private global::System.String _SeName; 
partial void OnSeNameChanging(global::System.String value); 
partial void OnSeNameChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Boolean AllowCustomerReviews 
{ 
    get 
    { 
     return _AllowCustomerReviews; 
    } 
    set 
    { 
     OnAllowCustomerReviewsChanging(value); 
     ReportPropertyChanging("AllowCustomerReviews"); 
     _AllowCustomerReviews = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("AllowCustomerReviews"); 
     OnAllowCustomerReviewsChanged(); 
    } 
} 
private global::System.Boolean _AllowCustomerReviews; 
partial void OnAllowCustomerReviewsChanging(global::System.Boolean value); 
partial void OnAllowCustomerReviewsChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Int32 ApprovedRatingSum 
{ 
    get 
    { 
     return _ApprovedRatingSum; 
    } 
    set 
    { 
     OnApprovedRatingSumChanging(value); 
     ReportPropertyChanging("ApprovedRatingSum"); 
     _ApprovedRatingSum = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("ApprovedRatingSum"); 
     OnApprovedRatingSumChanged(); 
    } 
} 
private global::System.Int32 _ApprovedRatingSum; 
partial void OnApprovedRatingSumChanging(global::System.Int32 value); 
partial void OnApprovedRatingSumChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Int32 NotApprovedRatingSum 
{ 
    get 
    { 
     return _NotApprovedRatingSum; 
    } 
    set 
    { 
     OnNotApprovedRatingSumChanging(value); 
     ReportPropertyChanging("NotApprovedRatingSum"); 
     _NotApprovedRatingSum = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("NotApprovedRatingSum"); 
     OnNotApprovedRatingSumChanged(); 
    } 
} 
private global::System.Int32 _NotApprovedRatingSum; 
partial void OnNotApprovedRatingSumChanging(global::System.Int32 value); 
partial void OnNotApprovedRatingSumChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Int32 ApprovedTotalReviews 
{ 
    get 
    { 
     return _ApprovedTotalReviews; 
    } 
    set 
    { 
     OnApprovedTotalReviewsChanging(value); 
     ReportPropertyChanging("ApprovedTotalReviews"); 
     _ApprovedTotalReviews = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("ApprovedTotalReviews"); 
     OnApprovedTotalReviewsChanged(); 
    } 
} 
private global::System.Int32 _ApprovedTotalReviews; 
partial void OnApprovedTotalReviewsChanging(global::System.Int32 value); 
partial void OnApprovedTotalReviewsChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Int32 NotApprovedTotalReviews 
{ 
    get 
    { 
     return _NotApprovedTotalReviews; 
    } 
    set 
    { 
     OnNotApprovedTotalReviewsChanging(value); 
     ReportPropertyChanging("NotApprovedTotalReviews"); 
     _NotApprovedTotalReviews = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("NotApprovedTotalReviews"); 
     OnNotApprovedTotalReviewsChanged(); 
    } 
} 
private global::System.Int32 _NotApprovedTotalReviews; 
partial void OnNotApprovedTotalReviewsChanging(global::System.Int32 value); 
partial void OnNotApprovedTotalReviewsChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Boolean Published 
{ 
    get 
    { 
     return _Published; 
    } 
    set 
    { 
     OnPublishedChanging(value); 
     ReportPropertyChanging("Published"); 
     _Published = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("Published"); 
     OnPublishedChanged(); 
    } 
} 
private global::System.Boolean _Published; 
partial void OnPublishedChanging(global::System.Boolean value); 
partial void OnPublishedChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
[DataMemberAttribute()] 
public global::System.Boolean Deleted 
{ 
    get 
    { 
     return _Deleted; 
    } 
    set 
    { 
     OnDeletedChanging(value); 
     ReportPropertyChanging("Deleted"); 
     _Deleted = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("Deleted"); 
     OnDeletedChanged(); 
    } 
} 
private global::System.Boolean _Deleted; 
partial void OnDeletedChanging(global::System.Boolean value); 
partial void OnDeletedChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public Nullable<global::System.DateTime> CreatedOnUtc 
{ 
    get 
    { 
     return _CreatedOnUtc; 
    } 
    set 
    { 
     OnCreatedOnUtcChanging(value); 
     ReportPropertyChanging("CreatedOnUtc"); 
     _CreatedOnUtc = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("CreatedOnUtc"); 
     OnCreatedOnUtcChanged(); 
    } 
} 
private Nullable<global::System.DateTime> _CreatedOnUtc; 
partial void OnCreatedOnUtcChanging(Nullable<global::System.DateTime> value); 
partial void OnCreatedOnUtcChanged(); 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
[DataMemberAttribute()] 
public Nullable<global::System.DateTime> UpdatedOnUtc 
{ 
    get 
    { 
     return _UpdatedOnUtc; 
    } 
    set 
    { 
     OnUpdatedOnUtcChanging(value); 
     ReportPropertyChanging("UpdatedOnUtc"); 
     _UpdatedOnUtc = StructuralObject.SetValidValue(value); 
     ReportPropertyChanged("UpdatedOnUtc"); 
     OnUpdatedOnUtcChanged(); 
    } 
} 
private Nullable<global::System.DateTime> _UpdatedOnUtc; 
partial void OnUpdatedOnUtcChanging(Nullable<global::System.DateTime> value); 
partial void OnUpdatedOnUtcChanged(); 

[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "ProductCategory_Product", "Product_Category_Mapping")] 
public EntityCollection<Product_Category_Mapping> Product_Category_Mapping 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Product_Category_Mapping>("eSalesModel.ProductCategory_Product", "Product_Category_Mapping"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Product_Category_Mapping>("eSalesModel.ProductCategory_Product", "Product_Category_Mapping", value); 
     } 
    } 
} 

[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "ProductManufacturer_Product", "Product_Manufacturer_Mapping")] 
public EntityCollection<Product_Manufacturer_Mapping> Product_Manufacturer_Mapping 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Product_Manufacturer_Mapping>("eSalesModel.ProductManufacturer_Product", "Product_Manufacturer_Mapping"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Product_Manufacturer_Mapping>("eSalesModel.ProductManufacturer_Product", "Product_Manufacturer_Mapping", value); 
     } 
    } 
} 

[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "ProductPicture_Product", "Product_Picture_Mapping")] 
public EntityCollection<Product_Picture_Mapping> Product_Picture_Mapping 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Product_Picture_Mapping>("eSalesModel.ProductPicture_Product", "Product_Picture_Mapping"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Product_Picture_Mapping>("eSalesModel.ProductPicture_Product", "Product_Picture_Mapping", value); 
     } 
    } 
} 
[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "ProductReview_Product1", "ProductReview")] 
public EntityCollection<ProductReview> ProductReviews 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<ProductReview>("eSalesModel.ProductReview_Product1", "ProductReview"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<ProductReview>("eSalesModel.ProductReview_Product1", "ProductReview", value); 
     } 
    } 
} 
[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "ProductSpecificationAttribute_Product", "Product_SpecificationAttribute_Mapping")] 
public EntityCollection<Product_SpecificationAttribute_Mapping> Product_SpecificationAttribute_Mapping 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Product_SpecificationAttribute_Mapping>("eSalesModel.ProductSpecificationAttribute_Product", "Product_SpecificationAttribute_Mapping"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Product_SpecificationAttribute_Mapping>("eSalesModel.ProductSpecificationAttribute_Product", "Product_SpecificationAttribute_Mapping", value); 
     } 
    } 
} 
[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "ProductVariant_Product", "ProductVariant")] 
public EntityCollection<ProductVariant> ProductVariants 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<ProductVariant>("eSalesModel.ProductVariant_Product", "ProductVariant"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<ProductVariant>("eSalesModel.ProductVariant_Product", "ProductVariant", value); 
     } 
    } 
} 
[XmlIgnoreAttribute()] 
[SoapIgnoreAttribute()] 
[DataMemberAttribute()] 
[EdmRelationshipNavigationPropertyAttribute("eSalesModel", "Product_ProductTag_Mapping", "ProductTag")] 
public EntityCollection<ProductTag> ProductTags 
{ 
    get 
    { 
     return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<ProductTag>("eSalesModel.Product_ProductTag_Mapping", "ProductTag"); 
    } 
    set 
    { 
     if ((value != null)) 
     { 
      ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<ProductTag>("eSalesModel.Product_ProductTag_Mapping", "ProductTag", value); 
     } 
    } 
} 

}

+0

您可以發佈您的模型? – 2012-08-08 02:05:09

+0

查看上面更新的帖子 – Matt 2012-08-08 02:22:35

回答

1

好吧,我想通了,是怎麼回事...基本上,我都在交易中,我運行這個在產品之前出口其他實體(類別)。問題在於,在添加所有類別後,我沒有呼叫SaveChanges() ...所以出現的錯誤是關於類別表格而不是產品表格,但是當我打電話給SaveChanges()時我添加了產品以及..非常困惑..我希望將來他們會更清楚地說出錯誤來自哪個表..這將節省大量的時間。

這是我的情況,而不是你可以看到爲什麼我沒有立刻拿起什麼是錯的:

using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes(30))) 
      using (var piloDB = new PiloEntities()) 
      using (var eSalesDB = new ESalesEntities()) 
      { 
       ExportCategories(piloDB, eSalesDB); //SaveChanges() not called in here 
       ExportProducts(piloDB, eSalesDB); //SaveChanges() is called in here 
       //export other...