views:

1295

answers:

1

Hi,

I'm trying to get a web app working based on the S#arp Architecture. At the moment I have a the below code for my entity.

[Serializable]
public abstract class EventBase : Entity
{
    #region Properties

    [DomainSignature]
    public virtual string Name { get; set; }

    public virtual string Description { get; set; }

    public virtual AgeRange Ages { get; set; }

    public virtual int Rating { get; set; }

    public virtual decimal Price { get; set; }

    public virtual string PhoneNumber { get; set; }

    public virtual string EmailAddress { get; set; }

    public virtual string Website { get; set; }

    public virtual EventState State { get; set; }

    #endregion

    protected EventBase() {}

    protected EventBase(string name, string description)
    {
        // ReSharper disable DoNotCallOverridableMethodsInConstructor
        Name = name;
        Description = description;
        Price = 0;
        State = EventState.New;
        // ReSharper restore DoNotCallOverridableMethodsInConstructor
    }
}

This is mapped using Fluent NHibernate as follows

public class EventBaseMap : AutoMap<EventBase>
{
    public EventBaseMap()
    {
        Id(x => x.ID).WithUnsavedValue(-1).GeneratedBy.Identity();

        Component<AgeRange>(x => x.Ages, m =>
         {
             m.Map(x => x.From).TheColumnNameIs("AgeFrom");
             m.Map(x => x.To).TheColumnNameIs("AgeTo");
         });

        JoinedSubClass<Music>("EventId", sub =>
         {
             sub.Map(x => x.Headliner);
         });
    }
}

I created a very simple repository using the very useful S#arp base repository classes.

public interface IEventRepository : INHibernateRepositoryWithTypedId<EventBase, int>
{
    List<EventBase> FindByName(string searchPhase);
}
public class EventRepository : NHibernateRepository<EventBase>, IEventRepository
{
    public List<EventBase> FindByName(string searchPhase)
    {
        return Session.Linq<EventBase>().Where(x => x.Name == searchPhase).ToList();
    }
}

I can create entities in the db and return all records. When I try to test the FindByName method I get the below error.

NHibernate.QueryException: could not resolve property: Name of: Model.Events.EventBase

Does anyone have any ideas? Is it a problem with my mapping?

Thanks,

A: 

This is using the Auto-mapping feature. I thought you only explicitly map properties that you want to override or that don't meet the conventions?

If I add an explicit mapping this solves the issue but I am still not sure why.

madcapnmckay
I noticed afterward, that's why I deleted the post. Sorry.
gcores