5

I have tried using the Reveal property in Fluent but I can't get it to compile with a collection. I want one of my collections in an entity to be protected and not accessible anywhere except in the entity itself. Is this possible? Thanks

Edit:

Here's the code I'm trying to use,

HasMany<Trip>(x => Reveal.Property<Trip>("_trips"));

I've also tried this code as well,

HasMany<Trip>(Reveal.Property<Organization>("_trips"));

Everytime my app runs, NHibernate says it can't map to "Property" or it throws an unknown exception.

CalebHC
  • 4,998
  • 3
  • 36
  • 42

2 Answers2

8

Assuming that Organization has a IList<Trip> the

HasMany<Trip>(Reveal.Property<Organization>("_trips"));

code should work. Check that it's a property and that you have protected getters and setters (privates will not work, since NHibernate will want to proxy the collection for lazyloading).

Bruno Lopes
  • 2,917
  • 1
  • 27
  • 38
  • 1
    As you say, I think the key is to make sure it's an IList, not a List. I'm just calling attention to that detail since I just read your answer and then proceeded to implement is as List... maybe this comment will help someone else avoid that mistake. – Seth Petry-Johnson Jan 09 '10 at 05:10
  • a very late comment on this topic. But Do you know if Nhibernate is satisfied with field. Or do you need to use properties? I would prefer field in my current project – Magnus Backeus Apr 20 '11 at 11:58
  • You can use fields. In FNH I think you need to change the .Access modifier and there should be an option for Field – Bruno Lopes Apr 20 '11 at 13:02
  • Yes, there are many variations on this syntax that seem right but don't work. What fooled me, was the Reveal.Member is the owning class not the list type – PandaWood Aug 03 '15 at 05:21
0

The simplest answer is to allow the mapping of protected internal virtual properties. This is document in the NHibernate Fluent documentation.

  1. Go to your AssemblyInfo.cs (under Properties) file and add the following: [assembly: InternalsVisibleTo("MyDomain.mapping")] where the string is the namespace of the mapping.
  2. create properties with the protected internal virtual access declarations.

        protected internal virtual IList<Clinician> __AppointmentMemberAttendees { get; set; }
    
  3. Map items just like normal.

        HasManyToMany(x => x.__AppointmentMemberAttendees)
               .Table("__AppointmentToAttendeesMember")
               .Cascade.None();
    
Juls
  • 658
  • 6
  • 15