-
Notifications
You must be signed in to change notification settings - Fork 6
Operation
Fúlvio edited this page Jan 23, 2018
·
7 revisions
1.1. MySql
string strconn = "Server=localhost;Database=testdb;Uid=root;Pwd=senha;SslMode=none";
MySqlConnection connection = new MySqlConnection(strconn);
1.2. Postgres
string strconn = "Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=senha;";
NpgsqlConnection connection = new NpgsqlConnection(strconn);
1.3. SqlServer
string strconn = "Server=.\\SqlExpress;Database=Test;User Id=sa;Password=senha;";
SqlConnection connection = new SqlConnection(strconn);
CREATE TABLE [Credit](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Description] [varchar](50) NOT NULL,
[Created] [date] NULL,
CONSTRAINT [PK_Credit] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
public class Credit
{
public Credit() { }
public int Id { get; set; }
public string Description { get; set; }
public DateTime? Created { get; set; }
}
var id = connection
.SoftBuild()
.From("Credit")
.AsInsert(new Dictionary<string, object>
{
["Description"] = credit.Description,
["Created"] = credit.Created
}) // Insert( ... ) old version
.SaveInsert<int>();
Note: the id
contains the value entered in the bank in the auto increment field.
connection
.SoftBuild()
.From("Credit")
.Where("Id", credit.Id)
.AsUpdate(new Dictionary<string, object>
{
["Description"] = credit.Description,
["Created"] = credit.Created
}) // Update( ... ) old version
.SaveUpdate();
connection
.SoftBuild()
.From("Credit")
.Where("id", id)
.AsDelete() //Delete() old version
.SaveUpdate();
connection
.SoftBuild()
.From("Credit")
.Where("Id", id)
.FindOne<Credit>()
IEnumerable<Credit> model = connection
.SoftBuild()
.From("Credit")
.OrderBy("Description")
.List<Credit>();