在实体框架3.5 sp1中调用SaveChanges()时出错

时间:2010-08-04 18:34:24

标签: asp.net entity-framework .net-3.5

当我在实体上下文中调用SaveChanges()方法时,我收到以下错误:

文化'en'是一种中性文化。它不能用于格式化和解析,因此不能设置为线程的当前文化。

我的浏览器文化设置为en-us,我的操作系统也是如此(在Windows 7,Vista和Server 2003上测试过)。

使用(SubscriptionEntity context = new 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:Culture'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(Nullable 1 cardinality) +90 System.Data.EntityUtil.UpdateRelationshipCardinalityConstraintViolation(String relationshipSetName, Int32 minimumCount, Nullable 1 maximumCount,String entitySetName,Int32 actualCount,String 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(IEntityStateManager stateManager,IEntityAdapter adapter)+210    System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)+117    System.Data.Objects.ObjectContext.SaveChanges(Boolean 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 ,列出`1 aoi)在D:\ DevProjects \ OslerDOTcom \ Main \ Source \ Code \ Osler.com \ Osler.PublicWeb.Subscription.Business \ Subscription.cs:150    c:\ Inetpub \ wwwroot \ dev.osler.com \ osler \ ContentTemplates \ CT_EmailSubscriptions.ascx.cs中的osler_ContentTemplates_CT_EmailSubscriptions.SaveSubscriptionInfo():338    c:\ Inetpub \ wwwroot \ dev.osler.com \ osler \ ContentTemplates \ CT_EmailSubscriptions.ascx.cs中的osler_ContentTemplates_CT_EmailSubscriptions.Button1_Click(Object sender,EventArgs e):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,String eventArgument)+13    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+175    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+1565

1 个答案:

答案 0 :(得分:0)

Bug in Entity Framework。实体框架将您的文化视为“en”(文化中立)而不是“en-us”