Comments (3)
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.
Hi, thanks for this. I'll change this ASAP. Next time you could issue a pull-request if you'd like.
from dommel.
I deployed v1.3.1 to NuGet.
from dommel.
Related Issues (20)
- DatabaseGeneratedOption.None not working HOT 4
- Combining predicate and One-to-many relations HOT 1
- SQLExpression does not use column mapping HOT 2
- Nuget 2.4.0 package issue HOT 2
- could you add a method to set the table name HOT 1
- missing selectAsync with joins HOT 1
- DateOnly and TimeOnly support HOT 2
- Not working with generic or abstract entity HOT 2
- SelectPaged and Multi Mapping HOT 1
- Issues resolving table names on derived types HOT 1
- Column Date in Postgres HOT 1
- Insert column with type of array HOT 1
- Automatic multi mapping N-hierarchy HOT 1
- One to Many Relation HOT 1
- Parentheses in SQL WHERE clause not working HOT 1
- Functions that may help HOT 1
- An error is occurring when executing Select - variable 'p' of type 'Escola.Entities.Aluno' referenced from scope '', but it is not defined HOT 1
- Multi-level foreign key relationships HOT 2
- Parentheses missing when combining multiple where statements
- DatabaseGeneratedOption.None not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dommel.