輪子?,我很任性,我要造不同的輪子,同時支持關係型和非關係型的框架有沒有html
新版數據查詢做了些調整,抽象了LabmdaQueryy和DBExtend,升級到版本4,非關係數據庫MongoDB被支持了!git
最近又好多人發各類框架,誰的好,用誰的?github
我的意見,想標準和穩定,EF,NH就好了,要個性,選一款好用的輪子吧mongodb
我的開發的框架始終是高級玩具,學習的好東西,不要較真,歡迎下載此高級玩具,猛擊底部GITHUB地址數據庫
歷史版本3介紹 CRL快速開發框架開源徹底轉到Github框架
當前版本結構更改以下ide
一句話描述,非關係型數據庫Mongodb能用CRL進行統一管理了,不用再寫各類各樣的實現函數
此功能依賴MongoDB官方驅動MongoDB.Driver學習
簡單示例測試
對象定義MongoDBModel.cs
public class MongoDBModel:CRL.IModel { public MongoDBModel() { //保持惟一 Id = new Guid(); } public Guid Id { get; set; } public string OrderId { get; set; } public int Status { get; set; } }
管理類實現MongoDBTestManage
public class MongoDBTestManage : CRL.BaseProvider<MongoDBModel> { public static MongoDBTestManage Instance { get { return new MongoDBTestManage(); } } }
數據鏈接建立
CRL.SettingConfig.GetDbAccess = (dbLocation) => { //可按type區分數據庫 var type2 = dbLocation.ManageType; if (type2 == typeof(Code.MongoDBTestManage)) { //實現MongoDB鏈接 return new CoreHelper.MongoDBHelper("mongodb://localhost:27017", "test2"); } return WebTest.Code.LocalSqlHelper.TestConnection; };
建立訪問對象
var instance = Code.MongoDBTestManage.Instance;
插入數據
instance.Add(new Code.MongoDBModel() { OrderId = "1212", Status = DateTime.Now.Second });
函數Count統計
int count = instance.Count(b => b.Status >= 0);
Group
var query = instance.GetLambdaQuery(); //group query.GroupBy(b => b.OrderId).Select(b => new { count = b.Status.SUM(), count2 = b.Status.COUNT() }); var list = query.ToDynamic(); foreach (var item in list) { var a = item.count; var key = item.OrderId; }
標準查詢
除了表明SQL特性的語法和函數不支持,其它都支持
var query2 = instance.GetLambdaQuery(); query2.Select(b => new { aa = b.Id, bb = b.Status }); query2.Where(b=>b.Status.In(1,2,3,4)&&b.OrderId.StartsWith("123"));//支持擴展方法 var result = query2.ToDictionary<Guid, int>();//返回字典 var result2 = query2.ToDynamic();//返回動態對象 var result3 = query2.ToList();//返回List<MongoDBModel>
更新刪除和以前調用方式保持一致
因爲MongoDB的特性,如下不能實現,調用可能會拋出異常
測試用例見開發文檔 /page/MongoDB.aspx
void TestMongoDB() { //依賴官方驅動MongoDB.Driver //MongoDBTest.Test(); //return; var instance = Code.MongoDBTestManage.Instance; //插入 instance.Add(new Code.MongoDBModel() { OrderId = "1212", Status = DateTime.Now.Second }); //函數Count int count = instance.Count(b => b.Status >= 0); var query = instance.GetLambdaQuery(); query.Where(b => b.Status > 10); var result3 = query.ToList();//返回List<MongoDBModel> //group query.GroupBy(b => b.OrderId).Select(b => new { count = b.Status.SUM(), count2 = b.Status.COUNT() }); var list = query.ToDynamic(); foreach (var item in list) { var a = item.count; var key = item.OrderId; } //標準查詢 var query2 = instance.GetLambdaQuery(); query2.Select(b => new { aa = b.Id, bb = b.Status }); //query2.Where(b=>b.Status.In(1,2,3,4)); var result = query2.ToDictionary<Guid, int>();//返回字典 var result2 = query2.ToDynamic();//返回動態對象 //刪除 instance.Delete(b => b.Status == 111); //更新 var item2 = instance.QueryItem(b => b.Status > 0); item2.Status = 123; instance.Update(item2); }
項目開源地址:https://github.com/hubro-xx/CRL3