I have some existing asp.net membership and role tables in legacy db, and I map them to new objects with Fluent Nhibernate.
I also generate the schema directly from Fluent Nhibernate, and then manually tune the generated sql script to exclude existing tables.
Can I tell Fluent Nhibernate to exclude certain tables from generation?
SchemaAction.None() in your ClassMap.
SchemaAction.None()
Another option is to create an attribute, say
public class DoNotAutoPersistAttribute : Attribute { }
AutoPersistenceModelGenerator Where AddEntityAssembly.
I succeeded with the attribute + convention:
public enum SchemaAction { None } [Serializable] [AttributeUsage(AttributeTargets.Class)] public class SchemaActionAttribute : Attribute { private readonly SchemaAction schemaAction = SchemaAction.None; public SchemaActionAttribute() { } public SchemaActionAttribute(SchemaAction schemaAction) { this.schemaAction = schemaAction; } public SchemaAction GetSchemaAction() { return schemaAction; } } /// <summary> /// overrides the default action for entities when creating/updating the schema /// based on the class having a Schema attribute (<see cref="SchemaActionAttribute" />) /// </summary> public class SchemaActionConvention : IClassConvention { public void Apply(IClassInstance instance) { object[] attributes = instance.EntityType.GetCustomAttributes(true); foreach (object t in attributes) { if (t is SchemaActionAttribute) { var a = (SchemaActionAttribute) t; switch(a.GetSchemaAction()) { case SchemaAction.None: instance.SchemaAction.None(); return; default: throw new ApplicationException("That schema action:" + a.GetSchemaAction().ToString() + " is not currently implemented."); } } } } } ... [SchemaAction(SchemaAction.None)] public class TextItem : Entity ...
Source: https://habr.com/ru/post/1716432/More articles:Using Doxygen with PHP in Ubuntu - phpSignificant performance degradation when migrating from Windows Server 2003 to 2008 (IIS 6 to IIS 7) - performanceHow to determine who is the creator of an object - c #Restarting daily or 100% uptime for enterprise applications? - enterpriseCEvent-like behavior with Boost.Thread - c ++How to insert a row between two rows and give it priority in the database? - sql-serverMore efficient jQuery - performanceКак создать экземпляр DataReceivedEventArgs или заполнить его данными? - c#C ++ simple error: "... uneclared (use this function first)" - c ++LuaJit increases stack / heap size - stackAll Articles