0

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?

Kelly
  • 3,292
  • 1
  • 24
  • 24

2 Answers2

1

Every entity that you want to Automap must have an Id property, or inherit from a class that has an Id property. Your Person class does neither.

Also, in my experience, all public methods in entities must be declared virtual (though this may not be required if you eager load everything).

Tom Bushell
  • 5,865
  • 4
  • 45
  • 60
  • The Person entity isn't the problem, read the exception Message. I didn't include the full person definition because I wanted to keep it simple. I also tried adding virtual to the GetStuff method, but that did not help. – Kelly Feb 07 '12 at 16:48
  • I saw the message, and it doesn't make any sense to me. Have no idea why FNH would treat a method as an entity, or what d__0 is. And it does complain about a missing ID, which was consistent with your sample code, so thought it might be worth a shot. Glad to hear you solved it - that's a new approach for me. – Tom Bushell Feb 08 '12 at 16:22
0

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));
    }
}
Kelly
  • 3,292
  • 1
  • 24
  • 24