0004: DbMetal is(n’t) so hard…
Few minutes ago I finally forced DbLinq to work and I’d like to tell you about it 🙂
First, I downloaded proper package of compiled binaries from DbLinq site and extracted archive to the temporary folder. Earlier I had prepared test SQLite database named test.lite with one table “Books” containing 27 columns that I described in previous post.
I’ve read in the Internet that DbMetal tool that downloaded package contains can be very helpful in creating foundations of database communication. Unfortunately documentation that I found is rather poor (later – too late – I discovered that source code package contains example of use with SQLite db), maybe in a distant future I will find huge manual that describes all features, must-knows, dangers etc., but I haven’t got this today, so later it will be rather useless for me. This situation proves that not only size matters 🙂 Easiness of use counts too 🙂 (sometimes I don’t know whether my jokes are really funny and meaningful in English too, I hope so).
Anyway, I had binaries but haven’t idea what to do with them. ORM theme is rather new for me (I have heard about it, but nothing more), so I started to read Internet 🙂 From scraps of information I created work plan:
1) Copy test.lite to the DbMetal.exe directory
2) Run DbMetal.exe with specific parameters to get .dbml file
3) Run DbMetal.exe again to get code file
4) Attach obtained dbml file to VS project
5) Easily and happily use all new features
Sounds great, doesn’t it? First step was a piece of cake 🙂
Second one was not. I opened console by “cmd” command in Start->Run…, went to DbMetal directory and typed:
Dbmetal.exe /provider:Sqlite "/conn Data Source=c:\DBLinq\test.lite" /dbml:testDbMap.dbml
Oops… Error message was:
“DbMetal: Could not load databaseConnectionType type ‘System.Data.SQLite.SQLiteConnection, System.Data.SQLite’. Try using the –with-dbconnection=TYPE option”.
I didn’t expect Spanish inquisition… so it takes about half of the hour to CAREFULLY read installation instruction – here I can see how poor my English is – step 1 of the section “To run DbMetal” states:
“Copy the ADO.NET provider assembly into the DbLinq installation directory. For example, for MySQL support the MySql.Data.dll assembly should be copied into the same directory as DbMetal.exe.”
Clear as my car’s windows (I had washed it yesterday :)) – I have to copy SQLite provider assembly System.Data.SQLite.dll to the DbMetal directory! So I did. Once again I run dbmetal and got message…
DbLinq Database mapping generator 2008 version 0.20
for Microsoft (R) .NET Framework version 3.5
Distributed under the MIT licence (http://linq.to/db/license)
>>> Reading schema from SQLite database
<<< Writing file 'testDbMap.dbml'
… and testDbMap.dbml file on disk. Another run of dbmetal with parameters:
Dbmetal.exe /code:testDbMap.cs testDbMap.dbml
Gave me a testDbMap.cs file. I opened VisualStudio and added .dbml file to the test project:
To see whether DB table has been mapped correctly I could open Designer view:
As we can see all 27 fields are available. Tomorrow I will try to show you the code. I hope that my posts aren’t boring and you will find something interesting in them.
Best regards, Paweł