Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any recommendations for Sqlite C# ORM code generation [closed]

Tags:

c#

sqlite

orm

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;
        }
    }
}
like image 638
Mark Redman Avatar asked Dec 19 '09 22:12

Mark Redman


2 Answers

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.

like image 111
Mark Ewer Avatar answered Oct 05 '22 23:10

Mark Ewer


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!)

like image 30
itowlson Avatar answered Oct 06 '22 00:10

itowlson