Search code examples
fluent-nhibernateautomapping

Fluent NHibernate: the entity '(method name)' doesn't have an Id mapped.


This is my first time trying Fluent NHibernate and Auto mapping. Unfortunately I have run into an issue that I cannot get past. I'm getting an error saying that a method on one of my classes cannot be mapped.

public class Person 
{
   public IEnumerable<string> GetStuff(){return stuff;}
}

The Exception Message is:

The entity '<GetStuff>d__0' doesn't have an Id mapped.

I even tried adding an IAutoMappingOverride to ignore the method (using map.IgnoreProperty).

Is it really trying to map a method? whats going on here?


Solution

  • I got around this by manually marking each Entity with an interface.

    public class MyAutomappingConfiguration : DefaultAutomappingConfiguration
    {
        public override bool ShouldMap(Type type)
        {
            return type.GetInterfaces().Contains(typeof (IEntity));
        }
    }