google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

DbMetal: The given key was not present in the dictionary. #258

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
From command prompt, I run: 

dbmetal /namespace:MyNamespace /provider:SQLite "/conn:Data Source=database.db" 
/code:CodeFile.cs

Instead of generating the code in CodeFile.cs, the tool exits right away with:

>>> Reading schema from SQLite database
DbMetal: The given key was not present in the dictionary.

I am using DbLinq 0.20 on Windows 7 64bit professional.

Original issue reported on code.google.com by igor.france on 9 Jun 2010 at 7:01

GoogleCodeExporter commented 9 years ago
Hi Igor! i'm using SQLite too. In order to understand reason of this error, can 
u post DB schema here?

Original comment by istillfi...@gmail.com on 16 Jun 2010 at 12:45

GoogleCodeExporter commented 9 years ago
I'd like to, but I'm not sure how. I have a .db file in which I created the 
tables and relationships with Visual Studio using System.Data.SQLite. I can 
send the .db file, but I'm not sure that's what you mean?

Original comment by igor.france on 16 Jun 2010 at 8:11

GoogleCodeExporter commented 9 years ago
The simple way is download little console sqlite3 client from 
http://sqlite.org/sqlite-3_6_23_1.zip , run from  console "sqlite3.exe 
c:\Path\To\Your\DB" and  input command ".schema". Output would like to:
"sqlite3 /home/kitt/Projects/dsm.sqlite
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema
CREATE TABLE "files" (
    "id" INTEGER PRIMARY KEY  AUTOINCREMENT UNIQUE , 
    "user" INTEGER REFERENCES "users"("id"),
    "file_type" TEXT NOT NULL DEFAULT 'image',
    "file_name" TEXT,
    "user_comment" TEXT,
    "content" BLOB
    );
CREATE TABLE "forum_themes"(
    "theme_id" INTEGER PRIMARY KEY  AUTOINCREMENT UNIQUE,
    "author" INTEGER  REFERENCES "users"("id"),
    "header" TEXT
    );
......................................"

Other way is run query to your database in any manner, even from your own 
simple console .net program:

using System;
using System.Data;
using System.Data.SQLite;

public class Program
{
   public static void Main()
   {
     SQLiteConnection con = new SQLiteConnection(@"Data Source=c:\path\to\your\DB");
     SQLiteCommand cmd = con.CreateCommand();
     cmd.CommandText = @"select sql from sqlite_master where not name like ""sqlite_%"" ";
     SQLiteDataReader rdr = cmd.ExecuteReader();
     while(rdr.Read())
     {
        Console.WriteLine(rdr["sql"].ToString());
     }
   }
}

Or u can run this query 
"select sql from sqlite_master where not name like 'sqlite_%' " from any 
program like SQLite Studio.

Original comment by istillfi...@gmail.com on 16 Jun 2010 at 12:23

GoogleCodeExporter commented 9 years ago
Thanks for the tips!
Here is the schema:

CREATE TABLE [BankAccounts] (
    [Account] int PRIMARY KEY NOT NULL,
    [Name] varchar(50) NOT NULL,
    [Bank] varchar(50) NOT NULL,
    CONSTRAINT [FK_BankAccounts_Transactions] FOREIGN KEY ([Account]) REFERENCES [Transactions] ([Account])
);
CREATE TABLE [Categories] (
    [ID] int PRIMARY KEY NOT NULL,
    [Name] varchar(100) NOT NULL,
    [ParentID] int,
    [Comment] ntext,
    [IsBusiness] bit NOT NULL,
    [TaxRateID] tinyint NOT NULL,
    CONSTRAINT [FK_Categories_Categories] FOREIGN KEY ([ID]) REFERENCES [Categories] ([ParentID]),
    CONSTRAINT [FK_Categories_Transactions] FOREIGN KEY ([ID]) REFERENCES [Transactions] ([CategoryID]),
    CONSTRAINT [FK_Categories_Payees] FOREIGN KEY ([ID]) REFERENCES [Payees] ([CategoryID]),
    CONSTRAINT [FK_Categories_TotalCategories] FOREIGN KEY ([ID]) REFERENCES [TotalCategories] ([CategoryID])
);
CREATE TABLE [Contacts] (
    [ID] int PRIMARY KEY NOT NULL,
    [Memo] nvarchar(50) NOT NULL,
    [Company] nvarchar(50),
    [ContactName] nvarchar(127),
    [Address] nvarchar(127),
    [Postcode] varchar(12),
    [Town] nvarchar(50),
    [CountryID] int NOT NULL DEFAULT 111,
    [Telephone1] varchar(20),
    [Telephone2] varchar(20),
    [Fax] varchar(20),
    [Email1] varchar(30),
    [Email2] varchar(30),
    [IsClient] bit NOT NULL DEFAULT 0,
    [Notes] text,
    CONSTRAINT [FK_Contacts_Payees] FOREIGN KEY ([ID]) REFERENCES [Payees] ([ContactID])
);
CREATE TABLE [Continents] (
    [ID] int PRIMARY KEY NOT NULL,
    [Name] varchar(30) NOT NULL,
    CONSTRAINT [FK_Continents_Countries] FOREIGN KEY ([ID]) REFERENCES [Countries] ([ContinentID])
);
CREATE TABLE [Countries] (
    [ID] int PRIMARY KEY NOT NULL,
    [Entity] varchar(120) NOT NULL,
    [ContinentId] int NOT NULL,
    [ISO_Alpha_2] varchar(2),
    [ISO_Alpha_3] varchar(3),
    [ISO_Name_EN] varchar(60),
    [ISO_Name_FR] varchar(60),
    [ISO_Num_3] smallint,
    [Fips_10_4] varchar(2),
    [Internet] varchar(5),
    [Wfb_Map] varchar(60),
    [Wfb_NameShort_EN] varchar(160),
    [Wfb_NameLongEN] varchar(160),
    [Wfb_NameShort_Local] varchar(160),
    [Wfb_NameLong_Local] varchar(160),
    [EEC] bit NOT NULL DEFAULT 0,
    CONSTRAINT [FK_Countries_0] FOREIGN KEY ([ID]) REFERENCES [Payees] ([CountryID])
);
CREATE TABLE [Invoices] (
    [InvoiceID] varchar(50) PRIMARY KEY NOT NULL,
    [ClientID] int NOT NULL,
    [ProjectID] int NOT NULL,
    [PeriodStart] datetime,
    [PeriodEnd] datetime,
    [Hours] int NOT NULL,
    [Amount] money NOT NULL DEFAULT 0,
    [TaxRateID] tinyint NOT NULL,
    [Notes] text,
    [Specifications] text,
    [Created] datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    [IsPaid] bit NOT NULL DEFAULT 0,
    [TransactionID] int
);
CREATE TABLE [Payees] (
    [ID] integer PRIMARY KEY NOT NULL,
    [Name] varchar(60) NOT NULL,
    [CategoryID] int,
    [ContactID] int,
    [CountryID] int NOT NULL DEFAULT 111,
    CONSTRAINT [FK_Payees_Transactions] FOREIGN KEY ([ID]) REFERENCES [Transactions] ([PayeeID])
);
CREATE TABLE [Projects] (
    [ID] int PRIMARY KEY NOT NULL,
    [Name] nvarchar(50) NOT NULL,
    [ClientID] int NOT NULL,
    [Description] ntext,
    [DateCreated] datetime NOT NULL,
    [IsActive] bit NOT NULL DEFAULT 1,
    [URL] varchar(128),
    [URLDev] varchar(128),
    [HourlyRate] int NOT NULL DEFAULT 85,
    [FixedRate] int NOT NULL DEFAULT 0
);
CREATE TABLE [TaxRates] (
    [ID] tinyint PRIMARY KEY NOT NULL,
    [Value] real NOT NULL,
    CONSTRAINT [FK_TaxRates_Categories] FOREIGN KEY ([ID]) REFERENCES [Categories] ([TaxRateID]),
    CONSTRAINT [FK_TaxRates_Transactions] FOREIGN KEY ([ID]) REFERENCES [Transactions] ([TaxTypeID])
);
CREATE TABLE [TotalCategories] (
    [ID] int PRIMARY KEY NOT NULL,
    [TotalID] int NOT NULL,
    [CategoryID] int NOT NULL
);
CREATE TABLE [Totals] (
    [ID] int PRIMARY KEY NOT NULL,
    [Name] nvarchar(30) NOT NULL,
    CONSTRAINT [FK_Totals_TotalCategories] FOREIGN KEY ([ID]) REFERENCES [TotalCategories] ([TotalID])
);
CREATE TABLE [Transactions] (
    [ID] int PRIMARY KEY,
    [Account] int NOT NULL,
    [Date] datetime NOT NULL,
    [TaxTypeID] tinyint NOT NULL,
    [PayeeID] int NOT NULL,
    [CategoryID] int,
    [Memo] varchar(255),
    [Comment] varchar(255),
    [IsVerified] bit NOT NULL DEFAULT 0
);

Original comment by igor.france on 16 Jun 2010 at 3:56

GoogleCodeExporter commented 9 years ago
Hi again. I check your issue, and find reason of problem. Fatc is that Sqlite 
not sense for register, but c# sense.

When you create DB, for SQLite next schema legal:

CREATE TABLE [Continents] (
   ...
    CONSTRAINT [FK_Continents_Countries] FOREIGN KEY ([ID]) REFERENCES [Countries] ([ContinentID])
);
CREATE TABLE [Countries] (
.....
    [ContinentId] int NOT NULL

SQLite understands that ContinentID and ContinentId the same. But DbMetal and 
c# stores temp data in dictianary while processing, and can't resolve foreign 
key from  Continents table "CONSTRAINT [FK_Continents_Countries] FOREIGN KEY 
([ID]) REFERENCES [Countries] ([ContinentID])", beacose Countries table has 
"ContinentId" column, rather "ContinentID". Fix your DB colunms and foreign 
keys names in one manner. I tried to do so, and all work succeeded. Here is 
result in attachment. 
Cheers.

Original comment by istillfi...@gmail.com on 17 Jun 2010 at 1:33

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, man!
Problem solved.

Original comment by igor.france on 17 Jun 2010 at 12:40