Hi,

I'm on S#arp Arch 1.0 RTM, trying to upgrade to 2009Q3 release. I've
been having issues with the change to FNH 1.0 RTM. The various changes
to mappings have made my app break.

Here is one of the several issues I'm trying to solve (that may be
related / cascading):

I have:
public class User
{
    public virtual Guid UserId { get; protected set; }
    public virtual string UserName { get; protected set; }
}

It represents the aspnet_Users table with only the relevant columns to
be mapped. This is the only entity that was not being automapped in my
pre-upgrade setup using:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Id(x => x.UserId);
        Map(x => x.UserName);
        WithTable("aspnet_Users");
    }
}

Everything else was getting automapped with some overrides to handle a
Money component, and JoinedSubclasses (these are separate upgrade
issues I'm dealing with, but one thing at a time here).

This used to be my PrimaryKeyConvention:
public class PrimaryKeyConvention : IIdConvention
{
    public bool Accept(IIdentityPart id) { return true; }

    public void Apply(IIdentityPart id)
    {
        id.ColumnName(id.Property.ReflectedType.Name + "Id")
           .WithUnsavedValue(System.Guid.Empty)
           .GeneratedBy.GuidComb();
    }
}

And my TableNameConvention:
public class TableNameConvention : IClassConvention
{
    public bool Accept(IClassMap classMap) { return true; }

    public void Apply(IClassMap classMap)
    {
        if (classMap.GetType() == typeof(UserMap))
            classMap.WithTable("aspnet_Users"); // This is how I side-
stepped the aspnet table
        else
            classMap.WithTable(Inflector.Net.Inflector.Pluralize
(classMap.EntityType.Name));
    }
}

Now I'm having issues with the required changes to work with FNH 1.0.
The Mapping process fails right after executing the ClassMap code
(which comes before all automapping), followed by the TableName
convention code, followed by the PrimaryKeyConvention code. Here is
the new code:

public class PrimaryKeyConvention : IIdConvention
{
    public void Apply(IIdentityInstance instance)
    {
        instance.Column(instance.Property.ReflectedType.Name + "Id");
        instance.UnsavedValue(System.Guid.Empty.ToString());
        instance.GeneratedBy.GuidComb();
    }
}

public class TableNameConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        instance.Table(Inflector.Net.Inflector.Pluralize
(instance.EntityType.Name));
    }
}

The failure is in PrimaryKeyConvention because instance.Property is
null. I tried to do an if(instance.Property != null) but that
terminates the mapping process early with a "the required attribute
'class' is missing" error. I also had an if (instance.EntityType !=
typeof(User)) in the TableNameConvention, but took out when it was
making no difference.

What is going on here? First of all, why is the AutoMapping processes
calling the conventions for the ClassMap? Second, why is the
PrimaryKenConvention getting passed an instance.Property == null?

Thanks (and sorry for the long post).

- Chris F.

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