Так что мой код, кажется, ломается, когда я сохраняю изменения. Я не могу обновить таблицу в своей локальной базе данных. Ищите помощь, пожалуйста. Прошу прощения, если это было больше, чем меня спрашивали. Я действительно не понимаю, как работает 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<T> 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
}
Вот Exception я получаю
"Сообщение" ключи сервера сгенерированных и серверные генерируемые значения не поддерживаются SQL Server Compact. "строка "
Пожалуйста, поделитесь 'модель tUser' тоже. – mindOfAi
Прошу прощения, что вы подразумеваете под моделью? – Dalton
Я говорю о классе 'tUser'. – mindOfAi