views:

249

answers:

0

Our relationships with the aspnet membership provider tables all reference the UserName field instead of the UserId field because we hate dealing with guids. But now I'm having troubles setting up a relationship between my orders table the aspnet_users table. Here are the mappings with unimportant fields taken out:

public class Aspnet_UserMap : ClassMap<Aspnet_User>
    {


        public Aspnet_UserMap()
        {
            WithTable("aspnet_Users");

            Id(x => x.UserId).GeneratedBy.Guid();
            Map(x => x.ApplicationId);
            Map(x => x.UserName);
            Map(x => x.LoweredUserName);
            Map(x => x.MobileAlias);
            Map(x => x.IsAnonymous);
            Map(x => x.LastActivityDate);

            HasManyToMany(x => x.Roles)
                .Cascade.All()
                .WithTableName("aspnet_UsersInRoles")
                .WithParentKeyColumn("UserId")
                .WithChildKeyColumn("RoleId");

            HasMany<Order>(x => x.Orders)
                .AsBag().Cascade.All().Inverse().KeyColumnNames.Add("UserName");
        }
    }
public class OrderMap : ClassMap<Order>
    {
        public OrderMap()
        {
            Id(x => x.Id);
            Map(x => x.Submitted);
            Map(x => x.DateSubmitted);


            References(x => x.User).ColumnName("UserName");
        }
    }

When I try to retrieve a an order I get the following exception:

System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)..

related questions