DBMetal generating an invalid class for sqlite_sequence

1.8k views Asked by At

I'm using DBLinq and DBMetal.exe to generate Linq-to-SQL like classes off an SQLite database. Every time I use DBMetal to regenerate my DataContext, it generates a class for sqlite_sequence. The trouble is is that sqlite_sequence isn't a proper table, so the class isn't complete.

The question is, can DBMetal.exe do a better job of generating this class, or can I tell DBMetal to ignore that class?

Thanks!

Here's my DBMetal.exe call

.\DbMetal.exe /namespace:Namespace /provider:SQLite "/conn:Data Source=Datasource.db" /code:CodeFile.cs 

Here's the actual generated SQL for sqlite_sequence (which is a system table):

CREATE TABLE sqlite_sequence(name,seq)

Here's the broken class that gets generated (notice the properties, name and seq, which don't have data types. That is the problem):

[Table(Name = "main.sqlite_sequence")]
public partial class SQLiteSequence : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private  _name;
    [DebuggerNonUserCode]
    [Column(Storage = "_name", Name = "name", DbType = "")]
    public  Name
    {
        get
        {
            return _name;
        }
        set
        {
            if (value != _name)
            {
                _name = value;
                OnPropertyChanged("Name");
            }
        }
    }       

    private  _seq;
    [DebuggerNonUserCode]
    [Column(Storage = "_seq", Name = "seq", DbType = "")]
    public  SEQ
    {
        get
        {
            return _seq;
        }
        set
        {
            if (value != _seq)
            {
                _seq = value;
                OnPropertyChanged("SEQ");
            }
        }
    }

    public SQLiteSequence() {}
}
1

There are 1 answers

0
sgwill On BEST ANSWER

I figured out a way. It was a multi-step process, but there's a method to do exactly what I wanted.

First, I generated a dbml from my database, using this command:

.\DbMetal.exe /namespace:Namespace /provider:SQLite "/conn:Data Source=Datasource.db" /dbml:CodeFile.dbml

Then I hand edited the dbml (which is just an XML file, of course) and removed the node for sqlite_sequence.

Finally, I generated the dbml.cs with this command:

.\DbMetal.exe /namespace:Namespace /provider:SQLite "/conn:Data Source=Datasource.db" /dbml CodeFile.dbml /code:CodeFile.dbml.cs

If I want to add a table, or new columns, I'll have to hand edit the dbml file, but now I have the control I want over my SQLite DataContext!