2017-02-21 12 views
0

変更を保存するとコードが壊れているようです。私は自分のローカルデータベースのテーブルを更新できません。助けを探してください。私に尋ねられている以上のものであれば謝ります。私はlinqがどのように動作しているのか、そして基本的なSQLコマンドを実行するために何が必要なのかを本当に理解していません。更新文Linqを使用したローカルデータベース

private void addUser() 
    { 
     try 
     { 

      var t = new tUser 
      { 
       Username = "test", 
       Password = "Password", 
       Email = "[email protected]", 
       Approved = true, 
       UserRoleID = 1, 
       First_Name = "test", 
       Last_Name = "test", 

      }; 
      this.db.AddTotUsers(t); 
      this.db.SaveChanges(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 

ここTUSER

using System; 
    using System.ComponentModel; 
    using System.Data.EntityClient; 
    using System.Data.Objects; 
    using System.Data.Objects.DataClasses; 
    using System.Linq; 
    using System.Runtime.Serialization; 
    using System.Xml.Serialization; 

    [assembly: EdmSchemaAttribute()] 
    namespace AVOSoftware 
    { 
#region Contexts 

/// <summary> 
/// No Metadata Documentation available. 
/// </summary> 
public partial class Database1Entities : ObjectContext 
{ 
    #region Constructors 

    /// <summary> 
    /// Initializes a new Database1Entities object using the connection string found in the 'Database1Entities' section of the application configuration file. 
    /// </summary> 
    public Database1Entities() : base("name=Database1Entities", "Database1Entities") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     OnContextCreated(); 
    } 

    /// <summary> 
    /// Initialize a new Database1Entities object. 
    /// </summary> 
    public Database1Entities(string connectionString) : base(connectionString, "Database1Entities") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     OnContextCreated(); 
    } 

    /// <summary> 
    /// Initialize a new Database1Entities object. 
    /// </summary> 
    public Database1Entities(EntityConnection connection) : base(connection, "Database1Entities") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     OnContextCreated(); 
    } 

    #endregion 

    #region Partial Methods 

    partial void OnContextCreated(); 

    #endregion 

    #region ObjectSet Properties 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    public ObjectSet<tUser> tUsers 
    { 
     get 
     { 
      if ((_tUsers == null)) 
      { 
       _tUsers = base.CreateObjectSet<tUser>("tUsers"); 
      } 
      return _tUsers; 
     } 
    } 
    private ObjectSet<tUser> _tUsers; 

    #endregion 

    #region AddTo Methods 

    /// <summary> 
    /// Deprecated Method for adding a new object to the tUsers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead. 
    /// </summary> 
    public void AddTotUsers(tUser tUser) 
    { 
     base.AddObject("tUsers", tUser); 
    } 

    #endregion 

} 

#endregion 

#region Entities 

/// <summary> 
/// No Metadata Documentation available. 
/// </summary> 
[EdmEntityTypeAttribute(NamespaceName="Database1Model", Name="tUser")] 
[Serializable()] 
[DataContractAttribute(IsReference=true)] 
public partial class tUser : EntityObject 
{ 
    #region Factory Method 

    /// <summary> 
    /// Create a new tUser object. 
    /// </summary> 
    /// <param name="userID">Initial value of the UserID property.</param> 
    /// <param name="username">Initial value of the Username property.</param> 
    /// <param name="password">Initial value of the Password property.</param> 
    /// <param name="userRoleID">Initial value of the UserRoleID property.</param> 
    /// <param name="first_Name">Initial value of the First_Name property.</param> 
    /// <param name="last_Name">Initial value of the Last_Name property.</param> 
    /// <param name="approved">Initial value of the Approved property.</param> 
    /// <param name="email">Initial value of the Email property.</param> 
    public static tUser CreatetUser(global::System.Int64 userID, global::System.String username, global::System.String password, global::System.Int32 userRoleID, global::System.String first_Name, global::System.String last_Name, global::System.Boolean approved, global::System.String email) 
    { 
     tUser tUser = new tUser(); 
     tUser.UserID = userID; 
     tUser.Username = username; 
     tUser.Password = password; 
     tUser.UserRoleID = userRoleID; 
     tUser.First_Name = first_Name; 
     tUser.Last_Name = last_Name; 
     tUser.Approved = approved; 
     tUser.Email = email; 
     return tUser; 
    } 

    #endregion 

    #region Primitive Properties 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.Int64 UserID 
    { 
     get 
     { 
      return _UserID; 
     } 
     set 
     { 
      if (_UserID != value) 
      { 
       OnUserIDChanging(value); 
       ReportPropertyChanging("UserID"); 
       _UserID = StructuralObject.SetValidValue(value); 
       ReportPropertyChanged("UserID"); 
       OnUserIDChanged(); 
      } 
     } 
    } 
    private global::System.Int64 _UserID; 
    partial void OnUserIDChanging(global::System.Int64 value); 
    partial void OnUserIDChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.String Username 
    { 
     get 
     { 
      return _Username; 
     } 
     set 
     { 
      OnUsernameChanging(value); 
      ReportPropertyChanging("Username"); 
      _Username = StructuralObject.SetValidValue(value, false); 
      ReportPropertyChanged("Username"); 
      OnUsernameChanged(); 
     } 
    } 
    private global::System.String _Username; 
    partial void OnUsernameChanging(global::System.String value); 
    partial void OnUsernameChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.String Password 
    { 
     get 
     { 
      return _Password; 
     } 
     set 
     { 
      OnPasswordChanging(value); 
      ReportPropertyChanging("Password"); 
      _Password = StructuralObject.SetValidValue(value, false); 
      ReportPropertyChanged("Password"); 
      OnPasswordChanged(); 
     } 
    } 
    private global::System.String _Password; 
    partial void OnPasswordChanging(global::System.String value); 
    partial void OnPasswordChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.Int32 UserRoleID 
    { 
     get 
     { 
      return _UserRoleID; 
     } 
     set 
     { 
      OnUserRoleIDChanging(value); 
      ReportPropertyChanging("UserRoleID"); 
      _UserRoleID = StructuralObject.SetValidValue(value); 
      ReportPropertyChanged("UserRoleID"); 
      OnUserRoleIDChanged(); 
     } 
    } 
    private global::System.Int32 _UserRoleID; 
    partial void OnUserRoleIDChanging(global::System.Int32 value); 
    partial void OnUserRoleIDChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.String First_Name 
    { 
     get 
     { 
      return _First_Name; 
     } 
     set 
     { 
      OnFirst_NameChanging(value); 
      ReportPropertyChanging("First_Name"); 
      _First_Name = StructuralObject.SetValidValue(value, false); 
      ReportPropertyChanged("First_Name"); 
      OnFirst_NameChanged(); 
     } 
    } 
    private global::System.String _First_Name; 
    partial void OnFirst_NameChanging(global::System.String value); 
    partial void OnFirst_NameChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.String Last_Name 
    { 
     get 
     { 
      return _Last_Name; 
     } 
     set 
     { 
      OnLast_NameChanging(value); 
      ReportPropertyChanging("Last_Name"); 
      _Last_Name = StructuralObject.SetValidValue(value, false); 
      ReportPropertyChanged("Last_Name"); 
      OnLast_NameChanged(); 
     } 
    } 
    private global::System.String _Last_Name; 
    partial void OnLast_NameChanging(global::System.String value); 
    partial void OnLast_NameChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.Boolean Approved 
    { 
     get 
     { 
      return _Approved; 
     } 
     set 
     { 
      OnApprovedChanging(value); 
      ReportPropertyChanging("Approved"); 
      _Approved = StructuralObject.SetValidValue(value); 
      ReportPropertyChanged("Approved"); 
      OnApprovedChanged(); 
     } 
    } 
    private global::System.Boolean _Approved; 
    partial void OnApprovedChanging(global::System.Boolean value); 
    partial void OnApprovedChanged(); 

    /// <summary> 
    /// No Metadata Documentation available. 
    /// </summary> 
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.String Email 
    { 
     get 
     { 
      return _Email; 
     } 
     set 
     { 
      OnEmailChanging(value); 
      ReportPropertyChanging("Email"); 
      _Email = StructuralObject.SetValidValue(value, false); 
      ReportPropertyChanged("Email"); 
      OnEmailChanged(); 
     } 
    } 
    private global::System.String _Email; 
    partial void OnEmailChanging(global::System.String value); 
    partial void OnEmailChanged(); 

    #endregion 


} 

#endregion 

}

のために生成されたクラスは、ここで私は

"メッセージ" サーバー生成キーおよびサーバ生成された値を取得しています例外ですSQL Server Compactではサポートされていません。 "文字列 "

+0

のために動作しますバージョン5以降、およびSQL Server Compactのサーバー生成されたキーにアップグレードする、Entity Frameworkの非常に古いバージョンを使用している、あまりにも、 'tUser'モデルを共有してください。 – mindOfAi

+0

申し訳ありませんが、モデルによってはどういう意味ですか? – Dalton

+0

私は 'tUser'クラスについて話しています。 – mindOfAi

答えて

0

SQL Server Compact Editionが自動生成キーをサポートしていないように見えます。あなたはUserIdを増やして値を提供するか、より機能豊富なSQL Serverを入手する必要があります。私はSQL Server Expressがそれを行うことができると確信しています。

0

あなたは(IDENTITY)の列があなた

関連する問題