I have been unsucesssful at trying different samples and techniques in getting XAF to use my own Legacy db User table with XAF Authentication and Roles classes and need some help.
I have a SqlServer existing Table named "User" with a existing Primary Key Guid of UserID , a column named UserName and other descriptive user columns populated as well.
Below is class I am using to defne in XAF app
[Persistent("[User]")]
public class Users : Person, IUserWithRoles, IAuthenticationActiveDirectoryUser, IAuthenticationStandardUser
{
private UserImpl user;
public Users(Session session)
: base(session)
{
this.user = new UserImpl(this);
}
public void ReloadPermissions()
{
Roles.Reload();
}
public bool ComparePassword(string password)
{
return user.ComparePassword(password);
}
public void SetPassword(string password)
{
user.SetPassword(password);
}
[Persistent]
private string StoredPassword
{
get { return user.StoredPassword; }
set
{
user.StoredPassword = value;
OnChanged("StoredPassword");
}
}
[Association("Users-Role")]
public XPCollection<UsersRole> Roles
{
get { return GetCollection<UsersRole>("Roles"); }
}
IList<IRole> IUserWithRoles.Roles
{
get
{
return new ListConverter<IRole, UsersRole>(Roles);
}
}
// [RuleRequiredField("User Name required", "Save", "The user name must not be empty")]
// [RuleUniqueValue("User Name is unique", "Save", "The login with the entered UserName was already registered within the system")]
public string UserName
{
get { return user.UserName; }
set
{
user.UserName = value;
OnChanged("UserName");
}
}
public bool ChangePasswordOnFirstLogon
{
get { return user.ChangePasswordAfterLogon; }
set
{
user.ChangePasswordAfterLogon = value;
OnChanged("ChangePasswordAfterLogon");
}
}
public bool IsActive
{
get { return user.IsActive; }
set
{
user.IsActive = value;
OnChanged("IsActive");
}
}
public IList<IPermission> Permissions
{
get
{
List<IPermission> result = new List<IPermission>();
foreach (UsersRole role in Roles)
{
result.AddRange(role.Permissions);
}
return result.AsReadOnly();
}
}
//Legacy existing
string fERPUserID;
[Size(20)]
public string ERPUserID
{
get { return fERPUserID; }
set { SetPropertyValue<string>("ERPUserID", ref fERPUserID, value); }
}
string fUserType;
[Size(1)]
public string UserType
{
get { return fUserType; }
set { SetPropertyValue<string>("UserType", ref fUserType, value); }
}
string fFName;
[Size(30)]
public string FName
{
get { return fFName; }
set { SetPropertyValue<string>("FName", ref fFName, value); }
}
string fLName;
[Size(30)]
public string LName
{
get { return fLName; }
set { SetPropertyValue<string>("LName", ref fLName, value); }
}
string femail;
public string email
{
get { return femail; }
set { SetPropertyValue<string>("email", ref femail, value); }
}
string ferpsacode;
[Size(10)]
public string erpsacode
{
get { return ferpsacode; }
set { SetPropertyValue<string>("erpsacode", ref ferpsacode, value); }
}
// public Users(Session session) : base(session) { }
// public User() : base(Session.DefaultSession) { }
public override void AfterConstruction() { base.AfterConstruction(); }
}
public class UsersRole : RoleBase, IRole
{
public UsersRole(Session session) : base(session) { }
[Association("Users-Role")]
public XPCollection<Users> Users
{
get { return GetCollection<Users>("Users"); }
}
IList<IUser> IRole.Users
{
get
{
return new ListConverter<IUser, Users>(Users);
}
}
}
After login attempt below is error I am receiving:
Unable to create 'Column' 'Oid'. Parent: 'User'. Error: Executing Sql 'alter table "dbo"."User" add "Oid" uniqueidentifier NOT NULL ROWGUIDCOL' with parameters '' exception 'System.Data.SqlClient.SqlException: Duplicate column specified as ROWGUIDCOL.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at DevExpress.Xpo.DB.ConnectionProviderSql.ExecSql(Query query)'