Inserting data
Using SQL statements:
1:int productId = Context.sql (@ "intoProduct" (Name, CategoryId)
2: values (@1);")
. Parameters ("The Warren Buffet", 1)
4: . Executereturnlastid<int> ();
Using Builder:
int productId = Context.insert ("Product")
. Column ("Name", "the Warren Buffet")
. Column ("CategoryId", 1)
4: . Executereturnlastid<int> ();
Use builder, and automatically map
Product Product = new product ();
Product. Name = "The Warren buffet";
Product. CategoryId = 1;
4:
5:product. ProductId = Context.insert<product> ("Product", product)
. Automap (x = X.productid)
7: . Executereturnlastid<int> ();
8:
The ProductID as a parameter to the Automap method is to indicate that ProductID does not need to be mapped because it is a database self-growing field.
Update data
Using SQL statements:
1:int rowsaffected = Context.sql (@ "Set Name = @
where ProductId = @1 ")
. Parameters ("The Warren Buffet", 1)
. Execute ();
Using Builder:
int rowsaffected = context.update ("Product")
. Column ("Name", "the Warren Buffet")
. Where ("ProductId", 1)
. Execute ();
Use builder, and automatically map:
1:product Product = Context.sql (@ "
where ProductId = 1 ")
3: . Querysingle<product> ();
Product. Name = "The Warren buffet";
5:
6:int rowsaffected = Context.update<product> ("Product", product)
. Automap (x = X.productid)
. Where (x = X.productid)
. Execute ();
Insert and Update-common Fill method
New Product ();
Product. Name = "The Warren buffet";
Product. CategoryId = 1;
4:
5:var Insertbuilder = Context.insert<product> ("Product", product). Fill (Fillbuilder);
6:
7:var Updatebuilder = Context.update<product> ("Product", product). Fill (Fillbuilder);
8:
9:public void Fillbuilder (Iinsertupdatebuilder<product> builder)
{
Builder. Column (x = x.name);
Builder. Column (x = X.categoryid);
}
14:
Delete
Delete data
Using SQL statements:
1:int rowsaffected = Context.sql (@ "
where ProductId = 1 ")
. Execute ();
Using Builder:
int rowsaffected = context.delete ("Product")
. Where ("ProductId", 1)
. Execute ();
Insert data
Using SQL:
int productId = Context.sql (@ "INSERT into Product (Name, CategoryId)
VALUES (@0, @1); ")
. Parameters ("The Warren Buffet", 1)
. Executereturnlastid<int> ();
Using a builder:
int productId = Context.insert ("Product")
. Column ("Name", "the Warren Buffet")
. Column ("CategoryId", 1)
. Executereturnlastid<int> ();
Using a builder with automapping:
Product Product = new product ();
Product. Name = "The Warren buffet";
Product. CategoryId = 1;
Product. ProductId = context.insert<product> ("Product", product)
. Automap (x = X.productid)
. Executereturnlastid<int> ();
We send in ProductId to the Automap method to get Automap to ignore and not map the ProductId since Entity field where the value is generated in the database.
Update data
Using SQL:
int rowsaffected = Context.sql (@ "Update Product set Name = @0
where ProductId = @1 ")
. Parameters ("The Warren Buffet", 1)
. Execute ();
Using a builder:
int rowsaffected = context.update ("Product")
. Column ("Name", "the Warren Buffet")
. Where ("ProductId", 1)
. Execute ();
Using a builder with automapping:
Product Product = Context.sql (@ "SELECT * FROM Product
where ProductId = 1 ")
. Querysingle<product> ();
Product. Name = "The Warren buffet";
int rowsaffected = context.update<product> ("Product", product)
. Automap (x = X.productid)
. Where (x = X.productid)
. Execute ();
We send in ProductId to the Automap method to get Automap to ignore and not map the ProductId since the identity F Ield that should not get updated.
Insert and Update-common Fill method
var product = new product ();
Product. Name = "The Warren buffet";
Product. CategoryId = 1;
var insertbuilder = context.insert<product> ("Product", product). Fill (Fillbuilder);
var updatebuilder = context.update<product> ("Product", product). Fill (Fillbuilder);
public void Fillbuilder (iinsertupdatebuilder<product> builder)
{
Builder. Column (x = x.name);
Builder. Column (x = X.categoryid);
}
Delete data
Using SQL:
int rowsaffected = Context.sql (@ "Delete from Product
where ProductId = 1 ")
. Execute ();
Using a builder:
int rowsaffected = Context.delete ("Product")
. Where ("ProductId", 1)
. Execute ();
(ext.) Fluentdata-insert, Update, Delete