Hi there.
Consider the following database:
Table User:
Id, PrimaryKey
Name

Table Group:
Id, PrimaryKey
Name

Table UserGroup:
UserId, PK, FK
GroupId PK, FK
Active


In the class User.cs, I have a method that gets all of the UserGroups
objects that the User has. I need to have them, because the
relationship between User and Group has a property (Active). Here is
one variant that I have tried:
        [HasAndBelongsToMany(typeof(UserGroup),
            Table="UserGroup",
            ColumnRef="userId",
            CompositeKeyColumnKeys=new string[] { "UserId",
"GroupId" },
            Inverse=true)]
        public IList<UserGroup> UserGroups
        {
            get { return _userGroups; }
            set { _userGroups = value; }
        }

The above code will give me this error:
Foreign key (FKB485EDD13D0DB589:UserGroup [UserId])) must have same
number of columns as the referenced primary key (UserGroup [UserId,
GroupId])

How should I do this?

The code for UserGroup.cs with ActiveRecord attributes follows:
    [Serializable]
    public class UserGroupKey
    {
        private int groupId;
        private int userId;

        [KeyProperty(Column="UserId")]
        public int UserId
        {
            get { return userId; }
            set { userId = value; }
        }

        [KeyProperty(Column="GroupId")]
        public int GroupId
        {
            get { return groupId; }
            set { groupId = value; }
        }

        public override int GetHashCode()
        {
            return userId ^ groupId;
        }

        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }
            UserGroupKey key = obj as UserGroupKey;
            if (key == null)
            {
                return false;
            }
            if (userId != key.userId || groupId != key.groupId)
            {
                return false;
            }
            return true;
        }
    }

    [ActiveRecord("UserGroup")]
    public class UserGroup : ActiveRecordBase<UserGroup>
    {
        private UserGroupKey _id;
        private int _active;

        [CompositeKey]
        public UserGroupKey Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [Property("Active")]
        public decimal Active
        {
            get { return _active; }
            set { _active = value; }
        }

        public UserGroup()
        {
        }
    }

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=.


Reply via email to