I am having difficulty automapping my object using Fluent NHibernate.
I have class called Document
for which the table already exist in SqlServer.
Class Packet
extends Document
and Have a member PacketDefinition
.
PacketDefinition
has a List
of Form
(not windows form but my own class) type.
I am trying to automap Packet
object using following configuration.
var mapping = CreateMappings();
_sessionFactory = Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2008.ConnectionString(
c => c.Server("machinename\\sql2012").Database("DatabaseName").TrustedConnection())
.ShowSql)
.Mappings(m => m.AutoMappings.Add(mapping))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
private static AutoPersistenceModel CreateMappings()
{
return AutoMap
.AssemblyOf<Packet>();
}
private static void BuildSchema(Configuration config)
{
new SchemaExport(config).Create(false, true);
}
The problem is when I try to automap Packet
class I get error saying
System.Data.SqlClient.SqlException : There is already an object named 'Document' in the database.
I understand that Document
table already exists in the database and I don't want to drop it. I tried Ignoring the base class using
AutoMap.AssemblyOf<Packet>().IgnoreBase<Document>();
but then automapping creates all the properties of Document
in Packet
table too, and that's not good.
If I create a separate database and then try running same code it works as Document
table doesn't exist in that database. I don't want to drop existing table as there is lot's of data in it.