Your UserPermission.allRoles is an List<T>, when it should be an IList<T>;
that's why you're getting the conversion error.

On Sun, Feb 8, 2009 at 5:27 PM, Pete <[email protected]> wrote:

>
> There are four tables that cover permission.
>
> aspnet_Roles
> aspnet_UsersInRole
> aspnet_User
> aspnet_Membership
>
> These are the standard MS tables.  I plan to just use these tables for
> reading only.   Then use the standard membership routines to modify
> the data.   Mostly I am doing this to test mapping on a set of tables
> everyone has.  My database is express.  I am having problems with the
> many to many
>
> Here are the EO:
>
>
> public class UserRoles
>    {
>        public virtual Guid RoleId { get; set; }
>        public virtual string RoleName { get; set; }
>        public virtual IList<UserPermission> UserWithRole { get;
> private set; }
>
>        public UserRoles()
>        {
>            UserWithRole = new List<UserPermission>();
>        }
>
>    }
>
>  public class UserPermission
>    {
>        public virtual Guid UserId { get; private set; }
>        public virtual string UserName { get; set; }
>        public virtual List<UserRoles> allRoles { get; set; }
>        public virtual Membership oneMembership { get; private set; }
>
>        public virtual void AssignMembership(Membership membership)
>        {
>            oneMembership = membership;
>            membership.Owner = this;
>        }
>
>        public virtual void AddUserRole(UserRoles userRole)
>        {
>            userRole.UserWithRole.Add(this);
>            allRoles.Add(userRole);
>        }
>
>        public UserPermission()
>        {
>            allRoles = new List<UserRoles>();
>        }
>    }
>
> public class Membership
>    {
>        public virtual Guid UserId { get; set; }
>        public virtual string Email { get; set; }
>        public virtual bool IsLockedOut { get; set; }
>        public virtual bool IsApproved { get; set; }
>        public virtual DateTime LastLoginDate { get; set; }
>        public virtual UserPermission Owner { get; set; }
>    }
>
>
> Here are my mappings
>
>  public class UserRolesMap : ClassMap<UserRoles>
>    {
>        public UserRolesMap()
>        {
>            Id(x => x.RoleId);
>            Map(x => x.RoleName);
>
>
>            HasManyToMany<UserPermission>(x => x.UserWithRole)
>              .Cascade.All().IsInverse()
>              .WithTableName("[SnapData].[dbo].[aspnet_UsersInRole]");
>
>            WithTable("[SnapData].[dbo].[aspnet_Users]");
>        }
>    }
>
> public class UserPermissionMap : ClassMap<UserPermission>
>    {
>        public UserPermissionMap()
>        {
>            Id(x => x.UserId);
>            Map(x => x.UserName);
>            //Map(x => x.LastActivityDate);
>            WithTable("[SnapData].[dbo].[aspnet_Users]");
>
>            HasManyToMany<UserRoles>(x => x.allRoles)
>                .Cascade.All()
>                .AsBag()
>                .WithTableName("[SnapData].[dbo].
> [aspnet_UserInRole]");
>
>            HasOne(x => x.oneMembership)
>                .PropertyRef(p => p.Owner)
>                .Cascade.All()
>                .FetchType.Join();
>
>        }
>    }
>
>  public class MembershipMap : ClassMap<Membership>
>    {
>        public MembershipMap()
>        {
>            Id(x => x.UserId);
>            Map(x => x.Email);
>            Map(x => x.IsLockedOut);
>            Map(x => x.IsApproved);
>            Map(x => x.LastLoginDate);
>
>            References(x => x.Owner)
>                .WithUniqueConstraint()
>                .TheColumnNameIs("UserId")
>                .LazyLoad()
>                .Cascade.None();
>
>            WithTable("[SnapData].[dbo].[aspnet_Membership]");
>        }
>    }
>
> You can tell from the UserPermission mapping that I am mapping one to
> one for aspnet_Membership to aspnet_Users.   I am also mapping many to
> many for aspnet_UserRoles to aspnet_User.  My one to one is working
> fine.   My many to many is not working.   I think it mght have to do
> lack of understanding of List<>  vs bag
>
> Error Message from nUnit:
> _Test_EOMapping.UserPermissionTest.DisplayOneRow:
> NHibernate.PropertyAccessException : The type
> NHibernate.Collection.Generic.PersistentGenericBag`1
> [SnapsInTime.EO.UserRoles] can not be assigned to a property of type
> System.Collections.Generic.List`1[SnapsInTime.EO.UserRoles] setter of
> SnapsInTime.EO.UserPermission.allRoles
>  ----> System.ArgumentException : Object of type
> 'NHibernate.Collection.Generic.PersistentGenericBag`1
> [SnapsInTime.EO.UserRoles]' cannot be converted to type
> 'System.Collections.Generic.List`1[SnapsInTime.EO.UserRoles]'.
>
> Thanks in advance
> Pete
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to