How do I map a protected collection in Fluent NHibernate?

后端 未结 2 811
滥情空心
滥情空心 2021-01-13 10:39

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 accessib

相关标签:
2条回答
  • 2021-01-13 11:08

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

    0 讨论(0)
  • 2021-01-13 11:29

    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();
      
    0 讨论(0)
提交回复
热议问题