Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Fluent NHibernate not to map a class property

I have a class that is mapped in fluent nhibernate but I want one of the classes properties to be ignored by the mapping.

With class and mapping below I get this error:

The following types may not be used as proxies: iMasterengine.Data.Model.Calendar: method get_HasEvents should be virtual

//my class
public class Calendar : IEntity {
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }
    public virtual string SiteId { get; set; }
    public virtual IList<CalendarEvent> Events { get; set; }
    //ignore this property
    public bool HasEvents { get { return Events.Count > 0; } }
}

//my mapping
public class CalendarMap : ClassMap<Calendar> {
    public CalendarMap() {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.SiteId);
        HasMany(x => x.Events).Inverse();
        //what do I put here to tell nhibernate
        //to ignore my HasEvents property?
    }
}
like image 529
modernzombie Avatar asked May 25 '09 18:05

modernzombie


2 Answers

You can just make HasEvents virtual in the class:

public virtual bool HasEvents { get { return Events.Count > 0; } }

You don't need to add anything to the mappings.

You only need to tell fluent to ingore a property if you are using Auto Mapping, which I don't think you are.

like image 115
UpTheCreek Avatar answered Oct 22 '22 17:10

UpTheCreek


map.IgnoreProperty(p => p.What);
like image 38
Owen Avatar answered Oct 22 '22 18:10

Owen