Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a convention <a href="http://wiki.fluentnhibernate.org/Conventions" rel="nofollow">http://wiki.fluentnhibernate.org/Conventions</a></p> <p>*UPDATED</p> <pre><code>public static class PrivatePropertyHelper { // from http://stackoverflow.com/questions/1565734/is-it-possible-to-set-private-property-via-reflection public static T GetPrivatePropertyValue&lt;T&gt;(this object obj, string propName) { if (obj == null) throw new ArgumentNullException("obj"); PropertyInfo pi = obj.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (pi == null) throw new ArgumentOutOfRangeException("propName", string.Format("Property {0} was not found in Type {1}", propName, obj.GetType().FullName)); return (T)pi.GetValue(obj, null); } } public class CustomTableNameConvention : IClassConvention { // Use this to set schema to specific value public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) { instance.Schema("My_NEw_Schema"); instance.Table(instance.EntityType.Name.CamelToUnderscoreLower()); } // Use this to alter the existing schema value. // note that Schema is a private property and you need reflection to get it public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) { instance.Schema(instance.GetPrivatePropertyValue&lt;string&gt;("Schema").Replace(".", "_")); instance.Table(instance.EntityType.Name.CamelToUnderscoreLower()); } } </code></pre> <p>You must use only one of he Apply methods.</p> <p>*UPDATE 2 I don't know I would recommend this but if you like to experiment this seems to work. Even more reflection :)</p> <pre><code> public static void SetSchemaValue(this object obj, string schema) { var mapping_ref = obj.GetType().GetField("mapping", BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.GetField | BindingFlags.NonPublic).GetValue(obj); var mapping = mapping_ref as ClassMapping; if (mapping != null) { mapping.Schema = schema; } } public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) { var schema = instance.GetPrivatePropertyValue&lt;string&gt;("Schema"); if (schema == null) { instance.Schema("My_New_Schema"); } else { instance.SetSchemaValue("My_New_Schema"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload