What is the equivalent NHibernate Code Mapping for the following Fluent NHibernate code:
Map(x => x.Orders).Access.CamelCaseField(Prefix.Underscore);
<
You have a couple of options to map a non-visible field by code.
Here are some, please note that I haven't tested them yet as written, but should help you anyways:
// Option 1:
public class CustomerMap : ClassMapping
{
public CustomerMap()
{
// ...
Bag("_orders", collectionMapping =>
{
//...
},
map => map.ManyToMany(p => p.Column("OrderId")));
}
}
// Option 2: No strings, but I'm not sure if this one would really work as is.
public class CustomerMap : ClassMapping
{
public CustomerMap()
{
// ...
Bag(x => x.Orders, collectionMapping =>
{
collectionMapping.Access(Accessor.Field),
//...
},
map => map.ManyToMany(p => p.Column("OrderId")));
}
}
// Option 3: No strings, but more convoluted.
public class Customer
{
internal class PrivatePropertyAccessors
{
public static Expression>> OrdersProperty = c => c._orders;
}
private readonly IList _orders = new List();
public IEnumerable Orders
{
get { foreach (var order in _orders) yield return order; }
}
}
public class CustomerMap : ClassMapping
{
public CustomerMap()
{
// ...
Bag(Customer.PrivatePropertyAccessors.OrdersProperty, collectionMapping =>
{
//...
},
map => map.ManyToMany(p => p.Column("OrderId")));
}
}