Domanda

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?

È stato utile?

Soluzione 2

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));
    }
}

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top