Giter Site home page Giter Site logo

Comments (3)

VGib avatar VGib commented on July 28, 2024

Here is my code (I don't know how to add project, feel free to ask me my project )

using System;
using Dapper.FluentMap.Mapping;
using Dapper.FluentMap.Dommel;

using System.IO;
using Dapper;
using Dommel;
using Dapper.FluentMap.Dommel.Mapping;
using Mono.Data.Sqlite;
using System.Reflection;

namespace DommelSample
{
    public class User
    {
        public int Id { get ; set; }
        public string Name { get; set; }
        public int Counter { get; set; }
    }

    public class UserMap : DommelEntityMap<User>
    {
        public UserMap()
        {
            ToTable ("user");
            Map (x => x.Id).ToColumn ("id").IsKey ();
            Map (x => x.Name).ToColumn ("name");
            Map (x => x.Counter).ToColumn ("counter");
        }
    }

    public  class MySqliteSqlBuilder : Dommel.DommelMapper.ISqlBuilder
    {
        public string BuildInsert(string tableName, string[] columnNames, string[] paramNames, PropertyInfo keyProperty)
        {
            return string.Format("insert into {0} ({1}) values ({2}); select last_insert_rowid() id",
                tableName,
                string.Join(", ", columnNames),
                string.Join(", ", paramNames));
        }
    }

    public class MainClass
    {
        static void CreateDatabaseTables (SqliteConnection connection)
        {
            connection.Execute ("create table user (id integer primary key autoincrement,name text, counter integer)");
        }

        public static void Main (string[] args)
        {
            Dapper.FluentMap.FluentMapper.Intialize (config => {
                config.AddMap(new UserMap());
                config.ForDommel();         
            }
            );
            DommelMapper.AddSqlBuilder (typeof(SqliteConnection), new MySqliteSqlBuilder());
            const string tmptestsqlite = "/tmp/test.sqlite";
            if (File.Exists (tmptestsqlite))
                File.Delete (tmptestsqlite);
            using (var connection = new SqliteConnection ("Data Source=/tmp/test.sqlite")) {

                CreateDatabaseTables (connection);

                connection.Insert (new User () { Name = "toto" });
                connection.Insert (new User () { Name = "tata" });
                connection.Insert (new User () { Name = "titi" });

                foreach (var test in connection.GetAll<User>()) {
                    test.Counter = 10;
                    connection.Update<User> (test);
                }


            }
        }
    }
}

from dommel.

henkmollema avatar henkmollema commented on July 28, 2024

Hi, thanks for this. I'll change this ASAP. Next time you could issue a pull-request if you'd like.

from dommel.

henkmollema avatar henkmollema commented on July 28, 2024

I deployed v1.3.1 to NuGet.

from dommel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.