Friday, December 07, 2007 7:43 PMIt would be nice if in a future version we could be able to generate SQL from the entities, like Castle Active Record supports:
using(StreamWriter sw = new StreamWriter("create_database.sql"))
Monday, January 07, 2008 7:25 PMYou can get all the DDL to a text writer right now actually. Just set the datacontext's Log property before you call CreateDatabase. I've just tried this now. You still have to actually create the database but, as it is created, all the DDL gets logged to the TextWriter which you have attached to the Log property.
Monday, January 07, 2008 7:35 PM
I've not used Castle Active Record myself, however I have used Rails - is this similar to the migrations? What is inside the SQL Script create database?
If you create a DataContext in your system (using SQLMetal or the Designer), Linq can already create the database for you by calling the DataContext.CreateDatabase() method.
The DataContext can also execute standard SQL by going DataContext.ExecuteCommand(sql).
Monday, January 07, 2008 11:51 PMAll I'm talking about is logging the SQL that is issued by the CreateDatabase method which you mention. It is a full script to create the database from scratch. I believe that's not the same as Rail's migrations.
Monday, January 07, 2008 11:54 PM
Oh, you can log all the queries using the DataContext.Log property. You can then out it to a file to write out everything.
I talked about how to get it to write everything to the console on my blog.
Hope this helps.
Tuesday, January 08, 2008 8:59 AM
Other posts you may find useful: