我收到以下錯誤,當我調用的SaveChanges我的實體上下文()方法時:錯誤調用的SaveChanges()在實體Framework 3.5 SP1中
文化「恩」是一箇中立的文化。它不能用於格式和解析,因此不能被設置爲線程的當前文化。
我的瀏覽器文化設置爲en-us,我的操作系統也一樣(在windows 7,vista和server 2003上測試過)。
使用(SubscriptionEntity上下文=新SubscriptionEntity()){
User user = new User();
user.First_Name = firstName;
user.Last_Name = lastName;
user.Company = company;
user.Job_Title = jobTitle;
user.Email_Address = email;
user.Address1 = address1;
user.Date_Created = DateTime.Now;
User_Mail_Preference_Language_Format user_mail_format_language = new User_Mail_Preference_Language_Format();
user_mail_format_language.Mail_Preferences_Format = context.Mail_Preferences_Format.FirstOrDefault(p => p.Mail_Preferences_Format_ID == mailFormat);
user_mail_format_language.Mail_Preferences_Language = context.Mail_Preferences_Language.FirstOrDefault(t => t.Mail_Preferences_Language_ID == languagePreference);
user.User_Mail_Preference_Language_Format.Add(user_mail_format_language);
foreach (int i in aoi)
{
User_Area_of_Interest user_aoi = new User_Area_of_Interest();
user_aoi.Area_of_Interest = context.Area_of_Interest.First(p => p.Area_of_Interest_ID == i);
user.User_Area_of_Interest.Add(user_aoi);
}
context.AddToUser(user);
context.SaveChanges();
錯誤: [NotSupportedException異常:文化成 'en' 是中性培養。它不能用於格式和解析,因此不能被設置爲線程的當前文化。] System.Globalization.CultureInfo.CheckNeutral(CultureInfo culture)+7484386 System.Globalization.CultureInfo.get_NumberFormat()+13 System.Globalization .NumberFormatInfo.GetInstance(的IFormatProvider formatProvider)89 System.Data.EntityUtil.ConvertCardinalityToString(可空1 cardinality) +90 System.Data.EntityUtil.UpdateRelationshipCardinalityConstraintViolation(String relationshipSetName, Int32 minimumCount, Nullable
1 maximumCount,字符串entitySetName,的Int32 actualCount,字符串otherEndPluralName,IEntityStateEntry stateEntry)26 System.Data.Mapping.Update.Internal.RelationshipConstraintValidator .ValidateConstraints()+417 System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()+59 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateMana GER stateManager,IEntityAdapter適配器)210 System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)117個 System.Data.Objects.ObjectContext.SaveChanges(布爾acceptChangesDuringSave)453個 System.Data.Objects.ObjectContext.SaveChanges ()+9 Osler.PublicWeb.Subscription.Business.Subscription.AddSubscription(String firstName,String lastName,String company,String jobTitle,String email,String address1,String address2,String city,String provinceState,String postalCode,String country, Int32 languagePreference,Int32 mailFormat,List`1 aoi)in D:\ DevProjects \ OslerDOTcom \ Main \ Source \ Code \ Osler.com \ Osler.PublicWeb.Subscription.Business \ Subscription.cs:150 osler_ContentTemplates_CT_EmailSubscriptions.SaveSubscriptionInfo()in c :\的Inetpub \ wwwroot的\ dev.osler.com \奧斯勒\ ContentTemplates \ CT_EmailSubscriptions.a scx.cs:338 osler_ContentTemplates_CT_EmailSubscriptions.Button1_Click(對象發件人,EventArgs e)如C:\的Inetpub \ wwwroot的\ dev.osler.com \奧斯勒\ ContentTemplates \ CT_EmailSubscriptions.ascx.cs:38個 System.Web.UI.HtmlControls。 HtmlButton.OnServerClick(EventArgs e)+111 System.Web.UI.HtmlControls.HtmlButton.RaisePostBackEvent(String eventArgument)+109 System.Web.UI.HtmlControls.HtmlButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument )10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,字符串eventArgument)13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection中POSTDATA)175 System.Web.UI.Page.ProcessRequestMain(布爾includeStagesBeforeAsyncPoint,布爾includeStagesAfterAsyncPoint)+1565
嘗試將您的代碼剝離到裸露的最小值,這將重現錯誤併發布代碼。同時發佈完整的異常消息,異常類型和堆棧跟蹤。 – Steven 2010-08-04 19:03:37