What is the equivalent NHibernate code mapping for the following Fluent NHibernate code:
Map(x => x.Orders).Access.CamelCaseField(Prefix.Underscore);
I spent all day trying to get this to work. Here is my code:
public class Customer { private readonly IList<Order> _orders = new List<Order>(); public virtual Guid ID { get; set; } public virtual string LastName { get; set; } public IEnumerable<Order> Orders { get { foreach (var order in _orders) yield return order; } } internal void AddOrder(Order order) { _orders.Add(order); } } public class CustomerMap : ClassMapping<Customer> { public CustomerMap() { Id<Guid>(x => x.Id); Component(x => x.LastName, y => { y.Property<string>(z => z.LastName); }); Bag(x => x._orders, collectionMapping => { collectionMapping.Table("CustomerOrders"); collectionMapping.Cascade(Cascade.None); collectionMapping.Key(k => k.Column("CustomerId")); }, map => map.ManyToMany(p => p.Column("OrderId"))); } }
This answers my question: https://groups.google.com/forum/#!topic/nhusers/wiH1DPGOhgU . I tried copying and pasting the code from my link (see below):
this.Bag( r => "privatefieldtomap", map => { map.Access(Access.Field); map.Table("table"); map.Key(k => k.Column("foreignkey")); }, r => r.Element(m => m.Column("columntomap")));
The error I get: Bag cannot be taken out of use.
c # nhibernate nhibernate-mapping
w0051977 Nov 28 '17 at 16:41 2017-11-28 16:41
source share