views:

441

answers:

1

Is there anything wrong with this code. I am not getting anything generated and no exceptions are thrown.

  public static void ExportSchema()
        {
            Configuration cfg = LoadDefaultConfiguration();
            Fluently.Configure(cfg)
                .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.Load("dnnSphere.Meta")))
                .ExposeConfiguration(c => new SchemaExport(c).SetOutputFile("myDDL.sql").Execute(true,true,false));
        }
+1  A: 

It depends on what you want to do. If you for instance is using a SQLite in memory db I never got it to work unless I specify the connection. This means I have to open a session and get the connection of the session first.

    protected InMemoryFixture()
    {

        Configuration config = GetConfig();
        ISessionFactory sessionFactory = config.BuildSessionFactory();


        ISession session = _sessionFactory.OpenSession();

        new SchemaExport(_config).Execute(true, true, false, session.Connection, Console.Out);

    }

    private Configuration GetConfig()
    {
        return GetMappings()
            .Database(SQLiteConfiguration.Standard.InMemory)
            .BuildConfiguration();
    }

    private FluentConfiguration GetMappings()
    {
        return Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssemblyOf<NewsMap>());
    }

Then there is also SchemaExport(cfg).Create(true, true); and SchemaUpdate(cfg) of course.

mhenrixon
No I was using MSSQL 2005. Problem was that one of the columns was named "Schema". Now that I solved that I tried SQLLite provider and I get an error:The IDbCommand and IDbConnection implementation in the assembly SQLite.NET could not be found. Ensure that the assembly SQLite.NET is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly. Is that what you get?
epitka
This is a common problem. First of all SQLite reference needs to be set to copy locally (reference properties), then you need to build the project before running it. Mind you I mostly use SQLite for testing but it sure is nifty! :) In the case of MSSQL 2005 you should be ok with what you had though I use new SchemaExport(cfg).Create(true, true); with create success here.
mhenrixon