tags:

views:

833

answers:

4

Hi,

Can anyone recommend an Sqlite C# ORM code generation tool.

I have found the Habanero framework, any comments on that?

Thanks

UPDATE

I have gone with Subsonic in this instance. To help anyone else out, here is a 'basic' example of creating a class and using Subsonic and Sqlite together.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using SubSonic;
using SubSonic.Schema;
using SubSonic.Repository;
using SubSonic.DataProviders;

namespace SubsonicSqliteTest
{
    public class User
    {
        public User()
        {
            ID = Guid.NewGuid();

            // Set Defaults
            FirstName = String.Empty;
            LastName = String.Empty;
            Username = String.Empty;
            Password = String.Empty;
            IsAdministrator = 0;
        }

        public Guid ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public int IsAdministrator { get; set; }
        public DateTime? CreatedDate { get; set; }
        public DateTime? LastUpdatedDate { get; set; }

        public static User Get(Guid id)
        {
            string databasePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Database.db");
            IDataProvider provider = ProviderFactory.GetProvider("Data Source=" + databasePath + ";Version=3;New=True;Pooling=True;Max Pool Size=1;", "System.Data.SQLite");
            var repository = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
            var users = from user in repository.All<User>()
                        where user.ID == id
                        select user;

            foreach (var user in users)
            {
                return user;
            }

            return null;
        }

        public User Save()
        {
            string databasePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Database.db");
            IDataProvider provider = ProviderFactory.GetProvider("Data Source=" + databasePath + ";Version=3;New=True;Pooling=True;Max Pool Size=1;", "System.Data.SQLite");
            var repository = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
            repository.Add(this);
            return this;
        }
    }
}
A: 

http://en.wikipedia.org/wiki/NHibernate

http://en.wikipedia.org/wiki/ADO.NET%5FEntity%5FFramework

you can also use the linq to sql magic thingy

Hellfrost
I'm pretty sure the "LINQ to SQL magic thingy" only works with SQL Server.
itowlson
im not... but it kinda sucks anyhow...this helps?http://sqlite.phxsoftware.com/
Hellfrost
LINQ to SQL is only for MSSQL server. But, the Entity Framework gives you a strong LINQ provider so you can do basically the same stuff.
Mark Ewer
+1  A: 

I don't know if it is exactly what you're looking for; have you already seen this?

http://sqlite.phxsoftware.com/

You can use it with ADO.NET 2.0 or the ADO.NET 3.5 Entity Framework.

eWolf
This also looks good, just trying to connect SubSonic to this...
Mark Redman
+2  A: 

Several .NET object-relational mappers support SQLite. See this question a list of .NET ORMs: of the ones mentioned there, I know that NHibernate and LightSpeed support SQLite, as does the Entity Framework does via the provider mentioned in eWolf's answer. I am not sure about others.

In terms of code generation, LightSpeed and the Entity Framework (via System.Data.SQLite) include tools for importing an existing SQLite database schema; I'm not sure about NHibernate. (Disclosure: I work for the company that makes LightSpeed; trying to keep the answer factual though!)

itowlson
+2  A: 

Others have already posted about NHibernate (especially with Fluent NHibernate) and ADO.Net Entity Framework which are both great. You may also want to look at SubSonic. If you are considering SQLite then your database requirements must be fairly simple and SubSonic's SimpleRepository option is super easy to use.

Mark Ewer
Yes, my requirements are ver simple, just need a very lightweight datastore and would rather try sqlite than access.
Mark Redman
The SubSonic SimpleRepository looks pretty good for small apps and quick proof-of-concepts! Any idea on how to connect a SimpleRepository to Sqlite DataProvider or how to configure an Sqlite connection string?
Mark Redman
I am going to go with Subsonic SimpleRepository, thanks for the help. (I have included a basic class that demonstrates Sqlite and Subsonic in the Question)
Mark Redman
Glad I could help out. Looks like you found the connections string, right?
Mark Ewer