让我们开启数据库无Linq、零sql时代(续)
第一部分 MQL
qq群:225656797
demo下载: 点此下载(既然下载,就支持该文,关注我的博客)
1.MQL概述
MQL是Moon.Orm 5.0中的全新设计,是在之前版本的革命性的升级.目的在于让我们的数据库开发打造为无Linq、零sql.它全面贴近标准sql,噪音低.原生.NET2.0支持、高性能、语法糖.多数库多数据源支持、操作便捷简单.
使用场景:1.NET 2.0; 2.觉得其他Orm性能低;3不喜欢linq;4.想更加便捷用sql
说明:一下以sqlserver为例.
2.MQL查询分类讲解
2.1 MQL的标准查询
var mm=ClassSet.
Select(ClassSet.ClassID,ClassSet.ClassName).
Where(ClassSet.ClassName.Contains("s").And(ClassSet.ClassID.BiggerThan(9)));
SELECT [Class].[ClassID],[Class].[ClassName] FROM [Class] WHERE [Class].[ClassName] LIKE @p1 AND [Class].[ClassID]>@p2
@p1=%s%
@p2=9
2.2 MQL的嵌套查询(含有Top查询:支持mysql、oracle、postgreSQL、sqlserver、sqlite)
var qiantao=ScoreSet.
SelectAll().
Where(
ScoreSet.UserID.
In(UserSet.
Select(UserSet.UserID).
Where(
UserSet.ClassID.
In(
ClassSet.
Select(ClassSet.ClassID).
Where(
ClassSet.ClassName.
Equal(c.ClassName).
And(ClassSet.ClassID.
BiggerThan(
0))
)
)
)
)
).
Top(
1);
SELECT TOP 1 [Score].* FROM [Score] WHERE [Score].[UserID] IN (SELECT [User].[UserID] FROM [User] WHERE [User].[ClassID] IN (SELECT [Class].[ClassID] FROM [Class] WHERE [Class].[ClassName]=@p1 AND [Class].[ClassID]>@p2 ) )
@p1=综合测试ClassName2
@p2=0
2.3 MQL的分组查询
var mql=ScoreSet.
Select(ScoreSet.ScoreM.
Sum().
AS(
"sum"),ScoreSet.TypeName).
Where(ScoreSet.ScoreM.BiggerThanOrEqual(100)).
GroupBy(ScoreSet.TypeName).
Having(ScoreSet.ScoreM.Sum().BiggerThan(300));
SELECT SUM([Score].[ScoreM]) AS 'sum',[Score].[TypeName] FROM [Score] WHERE [Score].[ScoreM]>=@p1 GROUP BY [Score].[TypeName] HAVING SUM([Score].[ScoreM])>@p2
@p1=100
@p2=300
2.4 MQL的连接查询
var m1=ClassSet.
Select(ClassSet.ClassID,ClassSet.ClassName)
.
LeftJoin(
UserSet.
Select(UserSet.UserID))
.
ON(ClassSet.ClassID.
Equal(UserSet.UserID))
.
Where(UserSet.UserID.
BiggerThan(
9));
SELECT [Class].[ClassID],[Class].[ClassName],[User].[UserID] FROM [Class] LEFT JOIN [User] ON [Class].[ClassID]=[User].[UserID] WHERE [User].[UserID]>@p1
@p1=9
var mql=ClassSet.
SelectAll().
Where(ClassSet.ClassID.
BiggerThan(
1))
.
Union(ClassSet.
SelectAll().
Where(ClassSet.ClassID.
BiggerThan(
2)));
var mql=ClassSet.
SelectAll().
Where(ClassSet.ClassID.
BiggerThan(
1))
.
UnionAll(ClassSet.
SelectAll().
Where(ClassSet.ClassID.
BiggerThan(
2)));
SELECT [Class].* FROM [Class] WHERE [Class].[ClassID]>@p1 UNION SELECT [Class].* FROM [Class] WHERE [Class].[ClassID]>@p2
@p1=1
@p2=2
SELECT [Class].* FROM [Class] WHERE [Class].[ClassID]>@p1 UNION ALL SELECT [Class].* FROM [Class] WHERE [Class].[ClassID]>@p2
@p1=1
@p2=2
3.MQL查询结果预览
public static void Main(
string[] args)
{
using (
var db=Db.
CreateDefaultDb()) {
db.TransactionEnabled=
true;
db.DebugEnabled=
true;
Console.
WriteLine(
"---------------嵌套查询---------------------");
var qiantao=ScoreSet.
SelectAll().
Where(
ScoreSet.UserID.
In(UserSet.
Select(UserSet.UserID).
Where(
UserSet.ClassID.
In(
ClassSet.
Select(ClassSet.ClassID).
Where(
ClassSet.ClassName.
Equal(c.ClassName).
And(ClassSet.ClassID.
BiggerThan(
0))
)
)
)
)
).
Top(
1);
Console.
WriteLine(
"---------------分组查询---------------------");
var mql=ScoreSet.
Select(ScoreSet.ScoreM.
Sum().
AS(
"sum"),ScoreSet.TypeName).
Where(ScoreSet.ScoreM.
BiggerThanOrEqual(
100)).
GroupBy(ScoreSet.TypeName).
Having(ScoreSet.ScoreM.
Sum().
BiggerThan(
300));
Console.
WriteLine(
"---------------连接查询---------------------");
var m1=ClassSet.
Select(ClassSet.ClassID,ClassSet.ClassName)
.
LeftJoin(
UserSet.
Select(UserSet.UserID))
.
ON(ClassSet.ClassID.
Equal(UserSet.UserID))
.
Where(UserSet.UserID.
BiggerThan(
9));
}
Console.WriteLine("---------------Union测试---------------------");
using (var db=Db.CreateDefaultDb()) {
db.TransactionEnabled=true;
db.DebugEnabled=true;
var mql=ClassSet.SelectAll().Where(ClassSet.ClassID.BiggerThan(1))
.Union(ClassSet.SelectAll().Where(ClassSet.ClassID.BiggerThan(2)));
}
}
QQAuDD8PrzP8nxNHBlk2qMXB5XAi9cQXQncz7qvM1gZAwBcm5e+XhfspXzRAn1ELAAAeOGwXgcAALgOrNcBAACuA+t1AACA68B6HQAA4DqwXgcAALgOrNcBAACuA+t1AACA68B6HQAA4DqwXgcAALgOrNcBAACuA+t1AACA68B6HQAA4DqwXgcAALgOrNcBAACuA+t1AACA68B6HQAA4DqwXn94lmVJNmqDZpcVluvsAQBgNazXr8AKkV73aiBjtuUVAwAAbIT1+hVYluVJO5cY26Xs27R3+zbzESG6BggAAElYr1+BSiaFarr6qruL1wqRVEf7mQwBAGALrNcviKvWro09zPTK+Nfe0HUAgEGwXr8avQqdWX9Hnl0z28v6RNcBAAbBev2xqSQzqdC3njX3zei3XevbBFxjdB0AYDSs1y+Cu5jW9kKqrVn0isF9fYCuAwCcxaj1uhAA2ndsv7MYpbQt5alm96Q3t315ruU253JnaH1on7MdAMbBev0iuA/Q6Dmbt8/4d5PR+zzcAQAGwefrF8EqpdbOpvQmvaHrAABTwXr9IqzW9WrNPULX7eIeXQcAGATr9YuwZb1+877Hbu1734cv/62CousAAINgvX4FrIImu2x0Ipx3vaoAAIC9YL3+8Ig3vcV74LaXPszgpuRmi64DAAyC9fpLpNR48Ub66OgAALA7rNdhUpqL/qT9iE8E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r2XrutAW0C5AaCE9To8Hl3KmlyvD4q+MVYTRB0AKt55+62u7fXXXu3T9RWP2lt6cbPxobbXM5FnKwAATMKTIid5kuxNui4Eu2xcp+vWQ5N1krw9LgAAwAjuIp3ZNul6+VHlXbarzy8rOV+xXnfDlWebNEsWDUfEBQAAOIZRuq4lUyxwK2GO/GjPWlnFq4EuymS2+AEAANiLo9frpRC6qtzUSPH6QLwOEE5ELE2VKqIOAACnc5Cuu6vqar96BRBlHPnRp/JOVrDLqwQAAIDtHKHr1ercXU9HSm+X3dZSnKrSSNKsWq+TvGcAAIAtVLru2uzzPnyJUDgt4bYx0vIjRbQZC10HAIBjsOv1ymDTet3qbnNde2utv5fnq3/hWS+dtVkXCDYAAEyC+z78/ezW78PfWp89C+Vunk16q+htz2D7ovQAAHAK0efrNyPq+7wPH0lvJOF2PX26ruv3Btw3ALa/JQAAAJDhuL9zq1qEyLkS7jpcp+tNGe6l2RddBwCAYzhB16PGFWeTGr+lPQOCDQAAk3Dmen2FxOYX6Og6AAC8QAbqun2/XX/qrN+fr866h9be9XP8+/AAAADH8M7bb338Y2/kt+6/c7vvZN6Q73p/Xoi6cMV6HQAALszrr73au7V1vfc/dWdjY2NjY2M7cVO6nv/v3AEAAGASQl1nY2NjY2Nje8TN0XU2NjY2Nja2x91+Xde7vn3HxsbGxsbGNuf2+muvrvn2HRsbGxsbG9uc2/8HmxObzquLQrIAAAAASUVORK5CYII=" alt="" height="353" width="538" />
第二部分 Moo.Orm数据操作篇
1.Moon.Orm初始化说明
1.1 配置文件说明
1.1.1默认配置
<connectionStrings> <add name="DefaultConnection" connectionString="Server=QSC-E15014A6665\SQLEXPRESS;Database=Test;uid=sa;Password=123456;" providerName="Moon.Orm,SqlServer" /> </connectionStrings>using (
var db=Db.
CreateDefaultDb()) {}
1.1.2其它配置
<connectionStrings> <add name="MyqlConnection" connectionString="mysql连接字符串" providerName="Mysql自定义dllName,Mysql" />
</connectionStrings>
using (
var db=Db.
CreateDbByConfigName("MysqlConnection")) {}
1.2 通过字符串直接初始化
using (
var db=
new SqlServer(
"连接字符串") {
}
2.Moon.Orm开启事务
using (
var db=Db.
CreateDefaultDb()) {
db.TransactionEnabled=
true;
//随便写许多逻辑,一个事务都在这个{}中
}
3.Moon.Orm开启调试模式
using (
var db=Db.
CreateDefaultDb()) {
db.DebugEnabled=
true;
var mql=ScoreSet.Select(ScoreSet.ScoreM.Sum().AS("sum"),ScoreSet.TypeName).
Where(ScoreSet.ScoreM.BiggerThanOrEqual(100)).GroupBy(ScoreSet.TypeName).
Having(ScoreSet.ScoreM.Sum().BiggerThan(300));
var sql=mql.
ToDebugSQL();//可以查看当前
查询语句}
4.Moon.Orm开启缓存模式
using (
var db=Db.
CreateDefaultDb()) {
db.StartCache(秒数);//查询用的缓存}
5.Moon.Orm添加数据
using (
var db=Db.
CreateDefaultDb()) {
db.DebugEnabled=
true;
Class c=
new Class();
c.ClassName=
"综合测试ClassName2";
db.
Add(c);
}
6.Moon.Orm删除数据
using (
var db=Db.
CreateDefaultDb()) {
db.DebugEnabled=
true;
db.
Remove(ClassSet.ClassID.
BiggerThan(
9));
}
7.Moon.Orm更新数据
using (
var db=Db.
CreateDefaultDb()) {
Class c=
new Class();
c.ClassName=
"综合测试ClassName2";
c.WhereExpression=ClassSet.ClassID.
BiggerThan(
9);
db.
Update(c);
}
8.Moon.Orm查询数据
8.1无实体类时,使用代码生成器生成实体类
List<T> ExecuteSqlToOwnList<T>(
string sql)
where T:
new() List<T> ExecuteSqlToOwnList<T>(
string sql,
params object[] values)
where T:
new()List<T> GetOwnList<T>(MQLBase mql)
where T:
new()
8.2无需实体类
//-----------------------------1.用MQL-------------------------------------- List<Dictionary<
string,MObject>>
GetDictionaryList(MQLBase mql)
var m1=ClassSet.
Select(ClassSet.ClassID,ClassSet.ClassName)
.
LeftJoin(
UserSet.
Select(UserSet.UserID))
.
ON(ClassSet.ClassID.
Equal(UserSet.UserID))
.
Where(UserSet.UserID.
BiggerThan(
9));
var list2=db.GetDictionaryList(m1);
//-----------------------------2.用sql语句------------------------------
List<Dictionary<
string,MObject>>
ExecuteSqlToDictionaryList(
string sql)List<Dictionary<
string,MObject>>
ExecuteSqlToDictionaryList(
string sql,
params object[] values)//支持参数化
DataSet ExecuteSqlToDataSet(
string sql)DataSet
ExecuteSqlToDataSet(
string sql,
params object[] values)
int ExecuteSqlWithNonQuery(
string sql)
8.3使用存储过程
DataSet
ExecuteProToDataSet(String procName,
params DbParameter[] parameters)
int ExecuteProWithNonQuery(String procName,
params DbParameter[] parameters)List<T> ExecuteProToOwnList<T>(String procName,
params DbParameter[] parameters)
where T:
new()
第三部分 MQL的邀请
MQL的现状:
1.目前基本完成了sqlserver的开发工作. 还需要oracle、mysql、postgreSQL、sqlite、db2的核心功能的开发,当然接口和核心模块都写好了,各类型数据库的模块我们需要实现基类即可.再次发出邀请,请您加入,发邮件给我 qsmy_qin@163.com
2.目前我们写代码生成器,我会定核心接口,您的加入只需实现此接口
您的参与,将奖励:
该版本的源代码
5.0之前的所有版本,我立即向大家开源,因还没有整理好,有需要者留言(关注我的博客),我发下载链接给您.