链接: http://pan.baidu.com/s/1i3xj0f7
解压密码:评论留邮箱即可获取,邮件回复于你:) 谢谢支持
Moon是一个 orm 框架.关于它和其他 实体框架、NH 的对比,大家可以阅读: www.cnblogs.com/humble/p/3426888.html
Moon.Orm,意在打造高性能、易用、便捷、易于维护、 多数据库数据源支持 的 Orm 框架。
全方位介绍: 最全面的介绍文档(点击这里)
1)发现实体框架不能满足大型系统中性能需求;(兄台就不要辩论了,咱们已经辩论太多累了:2015年5月1日13:59:46)
2)其他开源框架使用起来配置麻烦,如mybatis,nh..........
3)sql在VS中没有智能感知,如Dapper......
4)某些框架设计的一致性问题,语言晦涩.........
2.使用步骤
1.下载代码生成器生成model;
2.引用model及moon.orm到你的具体项目;
3.填写你的项目中配置文件;(关于配置文件:地址)
4.开始使用;
使用步骤:点击 去看看,这里很久以前的示例,大家可用新版本
代码生成器链接地址: 点击下载(这里是最新的)
对应的旗舰版的版本维护: 点击这里,可到这里随时更新
(下面代码对应的下载地址: http://pan.baidu.com/s/1mg3iZ12
注意:
1.请将数据库附加到您的数据库中.数据库下载地址: http://pan.baidu.com/s/1eQjIz7O
2.注意修改对应的配置文件中连接字符串;
)
/// <summary> /// 添加实体对象的测试 /// </summary> /// <returns></returns> public static void TestAddEntity(){ using (var db=Db.CreateDefaultDb()) { var startCount=GetProductCount(); Products p=new Products(); p.ProductName="ProductName"+DateTime.Now; p.Quantity=100; p.Remark="标记"; p.Unit="单元"; p.UnitPrice=12m; p.CategoryId=3; db.Add(p); //克隆一个p对象,然后添加到数据库中 var p2=p.Clone<Products>(); db.Add(p2); var endCount=GetProductCount(); Console.WriteLine("添加条数为:"+(endCount-startCount)); } } /// <summary> /// 删除实体对象的测试 /// </summary> public static void TestRemoveEntity(){ using (var db=Db.CreateDefaultDb()) { var startCount=GetProductCount(); Products p=new Products(); p.ProductName="ProductName"+DateTime.Now; p.Quantity=100; p.Remark="标记"; p.Unit="单元"; p.UnitPrice=12m; p.CategoryId=3; db.Add(p); //删除这条新加的数据 db.Remove<ProductsSet>(ProductsSet.ProductId.Equal(p.ProductId)); var endCount=GetProductCount(); Console.WriteLine("添加条数为:"+(endCount-startCount)); } } public static void TestUpdateEntity(){ using (var db=Db.CreateDefaultDb()) { db.DebugEnabled=true; var p=db.GetEntity<Products>(ProductsSet.SelectAll().Top(1)); Console.WriteLine(p.ProductName); p.ProductName=p.ProductName+DateTime.Now; p.Quantity=11; //必须通过设置WhereExpression来指定需要更新哪些数据 //--的确让用户有点误解,但这样可以指定更广泛的合符条件的数据如>100 and a<100 p.WhereExpression=ProductsSet.ProductId.Equal(p.ProductId); db.Update(p); var sql=db.CurrentSQL; p=db.GetEntity<Products>(ProductsSet.SelectAll().Top(1)); Console.WriteLine(p.ProductName); } }
/// <summary> /// 测试group及having语句 /// </summary> public static DictionaryList TestHaving(){ using (var db=Db.CreateDefaultDb()) { var mql=OrdersSet.Select(OrdersSet.OrderId.Count(),OrdersSet.CustomerId,OrdersSet.Finished) .Where(OrdersSet.CustomerId.SmallerThan(20)) .GroupBy(OrdersSet.CustomerId,OrdersSet.Finished) .Having(OrdersSet.OrderId.Count().BiggerThan(2)).Top(5); var sql=mql.ToDebugSQL();//等价sql语句 var list=db.GetDictionaryList(mql); return list; } }
SELECT TOP 5 COUNT([Orders].[OrderId]),[Orders].[CustomerId], [Orders].[Finished] FROM [Orders] WHERE [Orders].[CustomerId]<@p1 GROUP BY [Orders].[CustomerId] ,[Orders].[Finished] HAVING COUNT([Orders].[OrderId])>@p2 @p1=20 @p2=2
/// <summary> /// 测试join语句 /// </summary> public static DictionaryList TestJoin(){ using (var db=Db.CreateDefaultDb()) { var mql1=CustomersSet.Select(CustomersSet.CustomerName); var join=mql1.LeftJoin(OrdersSet.SelectAll()) .ON(OrdersSet.CustomerId.Equal(CustomersSet.CustomerId).And(OrdersSet.OrderId.SmallerThan(1000))) .Where(OrdersSet.OrderId.BiggerThan(1)).Top(10); var sql=join.ToDebugSQL();//等价sql语句 var list=db.GetDictionaryList(join); return list; } }
SELECT TOP 10 [Customers].[CustomerName],[Orders].* FROM [Customers] LEFT JOIN [Orders] ON ( [Orders].[CustomerId]= [Customers].[CustomerId] AND [Orders].[OrderId]<@p1 ) WHERE [Orders].[OrderId]>@p2 @p1=1000 @p2=1
/// <summary> /// 测试三条jion的语句 /// </summary> public static DictionaryList TestHighJoinMQL(){ using (var db=Db.CreateDefaultDb()) { var mql1=CustomersSet.Select(CustomersSet.CustomerName); var doubleJoin=mql1.LeftJoin(OrdersSet.Select(OrdersSet.OrderId.AS("_OrderId"))) .ON(OrdersSet.CustomerId.Equal(CustomersSet.CustomerId).And(OrdersSet.OrderId.SmallerThan(100))) ; var threeJoin=doubleJoin.LeftJoin(OrderDetailsSet.SelectAll()) .ON(OrderDetailsSet.OrderId.Equal(OrdersSet.OrderId).And(OrderDetailsSet.OrderId.BiggerThan(2))) .Where(OrdersSet.OrderId.SmallerThan(999)).Top(10); var sql=threeJoin.ToDebugSQL();//等价sql语句 var list=db.GetDictionaryList(threeJoin); return list; } }
SELECT TOP 10 * FROM (SELECT [Customers].[CustomerName],[Orders]. [OrderId] as "_OrderId" , [OrderDetails].* FROM [Customers] LEFT JOIN [Orders] ON ( [Orders].[CustomerId]=[Customers].[CustomerId] AND [Orders].[OrderId]<@p1 ) LEFT JOIN [OrderDetails] ON [OrderDetails]. [OrderId]=[Orders].[OrderId] AND [OrderDetails].[OrderId]>@p2 WHERE [Orders].[OrderId]<@p3 ) TopTemp1 @p1=100 @p2=2 @p3=999
/// <summary> /// 嵌套查询 /// </summary> /// <returns></returns> public static DictionaryList QianTao(){ using (var db=Db.CreateDefaultDb()) { var testBool=OrdersSet.SelectAll().Where( OrdersSet.CustomerId.In( CustomersSet.Select(CustomersSet.CustomerId).Where(CustomersSet.CustomerName.Contains("00")) ).And(OrdersSet.OrderId.BiggerThan(8)) ); var sql=testBool.ToDebugSQL();//等价sql语句 return db.GetDictionaryList(testBool); } }
SELECT [Orders].* FROM [Orders] WHERE [Orders].[CustomerId] IN (SELECT [Customers].[CustomerId] FROM [Customers] WHERE [Customers].[CustomerName] LIKE @p1 ) AND [Orders].[OrderId]>@p2 @p1=%00% @p2=8
/// <summary> /// Union测试 /// </summary> /// <returns></returns> public static DictionaryList TestUnion(){ using (var db=Db.CreateDefaultDb()) { var mql1=CustomersSet.SelectAll().Where(CustomersSet.CustomerId.BiggerThan(10)); var mql2=CustomersSet.SelectAll().Where(CustomersSet.CustomerId.SmallerThan(10)); var mql3=CustomersSet.SelectAll().Where(CustomersSet.CustomerId.Equal(10)); var mql=mql1.Union(mql2).Union(mql3).Top(1); var sql=mql.ToDebugSQL();//等价sql语句 return db.GetDictionaryList(mql); } }
SELECT TOP 1 * FROM (SELECT [Customers].* FROM [Customers] WHERE [Customers].[CustomerId]>@p1 UNION SELECT [Customers].* FROM [Customers] WHERE [Customers].[CustomerId]<@p2 UNION SELECT [Customers].* FROM [Customers] WHERE [Customers]. [CustomerId]=@p3 ) TopTemp1 @p1=10 @p2=10 @p3=10