#CSharpDataLib
Simple Data Tool Libaray for Operate Data in C# this is a useful tool if you want copy table in database;
- Connect Database
// Connect
using (SQLServerClientService = SQLServerClientService.GetInstance(conn2))
{
// Do Something
}
// Nested Connect
using (SQLServerClientService s1 = SQLServerClientService.GetInstance(conn1))
{
s1.ChangeDataBase("Demo1");
using (SQLServerClientService s2 = SQLServerClientService.GetInstance(conn1))
{
// Connect Success
}
}
- Insert
Data d = new Data(){ Age = 1 };
s1.InsertItem<Data>("Data", d);
// or just a Dictionry.
Dictionary<string, object> d = new Dictionary<string, object>();
s1.InsertItemDict("Data", d);
- SELECT && Update && Delete
s1.GetItemDict("Data", filter, new List<string>() { "Age", "Name" });
FilterCondition filter = new FilterCondition("Age", TableCompareType.EQ, 20);
s1.UpdateItemDict("Data", filter, "ID", Guid.NewGuid());
s1.RemoveItem<Data>("Data", filter);
- Batch Insert
s1.BulkInsertItemList<Data>("Data", List<Data> data);
s1.BulkInsertItemListDict("Data", List<Dictionary<string, object>> data);
s1.InsertItemList("Data", List<Dictionary<string, object>> data);
DataBase | CRUD | Paging | Batch Insert | Bulk Insert |
---|---|---|---|---|
SQLite |
√ | √ | √ | ✗ |
MySQL |
√ | √ | √ | ✗ |
SQLServer |
√ | √ | √ | √ |
Redis |
√ | √ | √ | ✗ |
MongoDB |
√ | √ | √ | ✗ |
FilterCondition filter = new FilterCondition("Age", TableCompareType.GTE, 20);
PageCondition page = new PageCondition(1, 20);
Dictionary<string, object> d = s1.GetItemList<Data>("Data", filter, ref page);
Transaction automatic begin when use GetInstance()
Except Redis
.
Redis
not support transaction, libaray will push operation to a Queue first,
and popup execute command after you call Commit()
.
Dictionary<string, object> d = new Dictionary<string, object>();
s1.SetItem("S1", d["ID"].ToString(), d);
s1.Commit();
s1.BulkLoadFromFile("Data", "D:/tmp.csv", "`");
in SQLServer, use GetCreateScript(name, true)
to export a table with index.
-
use
[TableFields(true)]
in Entity, then libaray will set and find value automatic. -
for
Mongodb
, addpublic ObjectId _id { get; set; }
in property. and add[BsonIgnoreExtraElements]
in class is needed. -
You should configure
replication
before use transaction.