Instead I’ll talk about how you can use the ruby script to generate the models from an existing database.
It adds the generated files to the visual studio project file in the same directory or you can specify one.
Currently it only supports Sql Server 2005. You need to create a project first in visual studio so we have a project file to add items to.
To use it you have to tell it which database it has to find by putting a database.yml file in your visual studio project directory.
The content of that database.yml file may look as follows
on windows you can use the following connection string
# # sqlserver: # database: northwind # host: localhost # username: sa # password: MaybePassword123 # # # on OSX and Linux you can connect to sql server through odbc (iODBC or unixODBC in combination with FreeTDS) # # sqlserver: # dsn: NorthwindSql # username: sa # password: MaybePassword123
when you’ve done that you can execute it like shown in the screenshot below:
I have a database.yml file in the directory and I execute the command ruby <> on linux and OSX you can chmod +x that path and then you don’t have to type ruby anymore.
That will generate the models for your database provided that your database conforms to the conventions needed for LightSpeed.
The next step would be to open visuals studio and build the project. The files got added in visual studio every entity are 2 files one with the generated code and one empty one that you can use to implement behavior on the model if you would want to.
The first picture shows how the solution explorer looks and the second one shows the results of the build without having touched one file after generation.
In the download there is a folder db which contains a slightly modified script from the Northwind database that comes with the samples for lightspeed. I used that database because it has every type of relationship and the script did conform to the lightspeed conventions :)