Forums

How to get XAF to use my own User Table

Last post 11/5/2009 12:13 AM by Mark Handzlik. 4 replies.
Sort Posts: Previous Next
  • Mark Handzlik

    How to get XAF to use my own User Table

    11/4/2009 1:19 AM
    • Not Ranked
    • Joined on 10/30/2009
    • Posts 13

    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)'

    Filed under: ,
  • Mohsen Benkhellat

    Re: How to get XAF to use my own User Table

    11/4/2009 9:51 AM
    • Top 75 Contributor
    • Joined on 11/20/2007
    • Montreal, QC
    • Posts 377

    Hi,

    Could it be that you are using DX BaseImpl implementation of user (which creates a user table) and you are trying to create another table Users that maps to a "User" table while it already exists?

    Mohsen

  • Dennis (DevExpress Support)

    Re: How to get XAF to use my own User Table

    11/4/2009 1:35 PM
    • Top 25 Contributor
    • Joined on 7/16/2007
    • Posts 1,695

    >>I have a SqlServer existing Table named "User" with a existing Primary Key Guid of UserID

    >> public class Users : Person,

    >>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.

    The solution lies in the info I quoted above. To fix the problem, do not inherit your Users class from the Person one because it already provides an Oid PK (inherited from the BaseObject) .

    Instead, inherit your Users class from the XPCustomObject or XPBaseObject orXPLiteObject and declare your own PK mapped to the UserID column.

    Let me know if you need a more detailed explanation.

    Support, R&D, .NET Team
    Join the XAF and XPO Fan Club!

    P.S.
    For your guaranteed official answer within 24 h, contact our Support Team. We are here to help address your issues.
  • Mark Handzlik

    Re: How to get XAF to use my own User Table

    11/4/2009 4:01 PM
    • Not Ranked
    • Joined on 10/30/2009
    • Posts 13

    Thanks Dennis that got my error to go away I now am getting a Second User table created in my db named SimpleUser. This table has Oid, UserName, FullName, IsActive, Is Administr... While my User legacy table has UserID, UserName, all my other User specific columns plus the IsActive, IsAdministrator ...

      I am not able to login when windows login box appears and I enter a username in my dbo.User table (all hve null passwords at this point and marked as Active).

    Below is current Class Code Thanks for any help you can provide:

      [Persistent("User")]
        public class Users : XPCustomObject, ISimpleUser, IAuthenticationActiveDirectoryUser, IAuthenticationStandardUser
        {
                public Users(Session session): base(session) {}
           
            private Guid _userID;
            private string _userName;
            private string _erpUserID;
            private string _userType;
            private string _fName;
            private string _lName;
            private string _email;
            private string _erpsacode;

            private bool _isActive;
            private bool _isAdministrator;
          
            private string _fullName;
            private string _password;
            private bool _changePasswordOnFirstLogon;

            public bool ComparePassword(string password) {
                return password == this._password;
            }

            public void SetPassword(string password) {
                this._password = password;
            }
          
            [Persistent("UserID")]
            [Key(true)]
            public Guid UserID
            {
                get { return _userID; }
                set { SetPropertyValue<Guid>("UserID", ref _userID, value); }
            }

            [Persistent("UserName")]
            [DisplayName("LogonName")]
        
            public string UserName {
                get { return _userName; }
                set {
                    _userName = value;
                    OnChanged("UserName");
                }
            }

          
            [Persistent]
            [Size(20)]
            public string ERPUserID
            {
                get { return _erpUserID; }
                set { SetPropertyValue<string>("ERPUserID", ref _erpUserID, value); }
            }
     
           
            [Persistent]
            [Size(1)]
            public string UserType
            {
                get { return _userType; }
                set { SetPropertyValue<string>("UserType", ref _userType, value); }
            }


          
            [Persistent]
            [Size(30)]
            public string FName
            {
                get { return _fName; }
                set { SetPropertyValue<string>("FName", ref _fName, value); }
            }


           
            [Persistent]
            [Size(30)]
            public string LName
            {
                get { return _lName; }
                set { SetPropertyValue<string>("LName", ref _lName, value); }
            }

      
          
            [Persistent]
            public string email
            {
                get { return _email; }
                set { SetPropertyValue<string>("email", ref _email, value); }
            }

           
            [Persistent]
            [Size(10)]
            public string erpsacode
            {
                get { return _erpsacode; }
                set { SetPropertyValue<string>("erpsacode", ref _erpsacode, value); }
            }

            [Persistent("FullName")]
            public string FullName {
                get { return _fullName; }
                set {
                    _fullName = value;
                    OnChanged("FullName");
                }
            }
            [Persistent("IsActive")]
            [DisplayName("IsActive")]
            public bool IsActive {
                get { return _isActive; }
                set {
                    _isActive = value;
                    OnChanged("IsActive");
                }
            }
            [Persistent("IsAdministrator")]
            [DisplayName("IsAdministrator")]
            public bool IsAdministrator {
                get { return _isAdministrator; }
                set {
                    _isAdministrator = value;
                    OnChanged("IsAdministrator");
                }
            }
           
            [Persistent]
            protected string Password {
                get { return _password; }
                set {
                    _password = value;
                    OnChanged("Password");
                }
            }
            [Persistent("ChangePasswordOnFirstLogon")]
            public bool ChangePasswordOnFirstLogon
            {
                get { return _changePasswordOnFirstLogon; }
                set
                {
                    _changePasswordOnFirstLogon = value;
                    OnChanged("ChangePasswordOnFirstLogon");
                }
            }

        }

  • Mark Handzlik

    Re: How to get XAF to use my own User Table

    11/5/2009 12:13 AM
    • Not Ranked
    • Joined on 10/30/2009
    • Posts 13

    Never mind, found out what I was doing wrong. Forgot to set RoleType and UserType properties in the WinApplication module.

    Thanks for the help.

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.