EF架构~有时使用SQL更方便
在进行统计时,尤其是按月进行统计,由于我们采用的时间是一个2015-12-12日这种,所以在linq你无法进行拆分,你拆分了在发到SQL时也会报错,因为SQL那边更新不需要你.net的方法,人家SQL只认自己的方法,哈哈,这也是正常的,为了解决这个问题,我们有时也需要使用纯SQL,当前也是基于EF的,通过EF的上下文把SQL语句发到数据库。
下面是一个比较复杂的统计,按月把某个用户的某个任务进行求和及求总数的统计,看一下代码
var idArr = user_FighterRepository.GetModel(i => i.ParentID == companyId).Select(i => i.UserID).ToList();
string para= string.Join(",", idArr);
var linq = Db.Database.SqlQuery<FighterTaskTotalDTO>(
@"SELECT CONVERT(CHAR(7), Day, 120) as TotalDate,
COUNT(*) as TaskCount,
FighterID ,
SUM(FinishedNumber) as FinishedCount
FROM dbo.Count_Fighter_ByDay
GROUP BY FighterID ,
CONVERT(CHAR(7), Day, 120)
HAVING FighterID IN ("+para+")");
return linq.ToList();
看你下SQL的结果
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQ8AAAC/CAIAAABv8M6oAAAN/0lEQVR4nO2dP27jPBTEdaEErl3lCgGSK7hPsUm7N0iKIHuJdAl8hi0XH9zlMPoK2xIlktKj9MinkeYHYeF1ZHseyRH1b+yqxuTu7s5aggJYVWCpVefu7q46Pzr9+wu0/P79u+k5czEbqQJLbaby6RZWsUK1mcqnW1jFCtVmKj/glj8PVZ+H14S3/nra3T4dzw+c93h8z95zU5Q3arvL8ddNDuWSKnrttvv1maQ8UwfNVatSgrN+gQ7yyx+YW14fq/s/E+p0O6Nd5/PlNlJVeq+PbecGlQs+/fjrpmqffH2c3B+DpQ2NP/dVsTfxnxe2ZGoHZVI7oeuv65fpIL/8Ym5JbEeB9Gxu+Xy5vXn5mtT6KaVJx5/8zWe5JbPa9PaJr1+og/zyxW5pJ9z7P/8+X26rqqrO/nb3fx7f451xfcPu+p23cj5lqDmS3NKX50ziu1+fjsjXx7OMAVe3LdCt7vz462l3+/TyEClt8vgL7jiNflyvJ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rWamP3dL23QjpIzP7m5y4ADWy7ipph+37d7LzqOfnYZ2xty1Z2eceX7/xm/tk2TOxs6YP8D6DVzzAZbU6jzPG226Fv39q3Fay1wtMpO/v2FkZ8zmtIGjyJXxYmcx5njrFuv07LjE6ij8xmqcTzYJmcykYc1kTRnTde6m5g/ge8YAEEwZA0AwZQwAwZQxAARTxgAQTBkDQDBlDADBlDEABFPGABBMGQNAsIefAEAoO2MACKaMASCYMgaAYMoYAIIpYwAIpowBIJgyBoBgyhgAgmXLuK3LolfW7fJ0crLruq5rqvmZ4bnzBzK/5P5qnNM8CZnMpFktiqJqVk9ydgYLR5Yr47Yuh/HVVP3ca+uyn2rjyWHuTVLe1uV6CY9P2bkaZ5RJQjYzaVjTZypgEgYLh3fvMnVbl18BbqpxhzGezf2Ytuua/atxWstcLTOTvYqzcmmHUzNYOLTtMk7G3yTJm/WZvUbYVJPRuH81zmuRq9XM9OeWV6SzJzkjg4VDWy/jppp+2LZ7LzsfmtlZaGfMXXt2xhvP3zjJCUkCh7Z+A9e8QpNanad6o03X/gfYvxqntczVIjPZ+xvyNz1wcgYLh5Yr4/6S8vxu1Oz9z8lF6eTsuMTqJcJvrMb5ZJOQyUwa1rSB3UpNwmDh8HzPGACCKWMACKaMASCYMgaAYMoYAIIpYwAIpowBIJgyBoBgyhgAgiljAAj28BMACPXwz3/+cTgcDofDEXgoY4fD4XA4go//AejQ2wqT/tRdAAAAAElFTkSuQmCC" alt="" />
最后需要注意一点,就是你的SQL语句的每个字段必须要有别名,如你的count(*)统计,需要为它起的别名,并且你的别名要和EF映射的实体属性对应!
EF架构~有时使用SQL更方便的更多相关文章
- EF架构~过滤导航属性等,拼接SQL字符串
拼接T-SQL串,并使它具有通用性 好处:与服务器建立一次连接,给服务器发一条SQL命令,即可实现 代码如下: 1 /// <summary> 2 /// 构建Insert语句串 3 // ...
- EF架构~数据分批批量提交
回到目录 对于大数据量提交,包括插入,更新和删除,我始终不建议用EF自带的方法,因为它会增加与数据库的交互次数,一般地,EF的一个上下文在提交时会打开一个数据连接,然后把转换成的SQL语句一条一条的发 ...
- EF架构~codeFirst从初始化到数据库迁移
一些介绍 CodeFirst是EntityFrameworks的一种开发模式,即代码优先,它以业务代码为主,通过代码来生成数据库,并且加上migration的强大数据表比对功能来生成数据库版本,让程序 ...
- EF架构~关系表插入应该写在事务里,但不应该是分布式事务
回到目录 这个标题很有意思,关系表插入,就是说主表和外表键在插入时,可能会有同步插的情况,如在建立主表时,扩展表需要同步完成数据的初始化工作,而对于多表插入时,我们为了保证数据的一致性会针它写在事务中 ...
- EF架构~基于EF数据层的实现
回到目录 之前写过关于实现一个完整的EF架构的文章,文章的阅读量也是满大的,自己很欣慰,但是,那篇文章是我2011年写的,所以,技术有些不成熟,所以今天把我的2014年写的EF底层架构公开一下,这个架 ...
- EF架构~通过EF6的DbCommand拦截器来实现数据库读写分离~终结~配置的优化和事务里读写的统一
回到目录 本讲是通过DbCommand拦截器来实现读写分离的最后一讲,对之前几篇文章做了一个优化,无论是程序可读性还是实用性上都有一个提升,在配置信息这块,去除了字符串方式的拼接,取而代之的是sect ...
- 在我的职业生涯中,没有一种技能比 SQL 更有用!
作者 | Craig Kerstiens 译者 | 阿拉丁 创业公司 CitusData(CitusData 是一家将 PostgreSQL 商业化的初创企业,也是 PostgreSQL 社区领导者, ...
- EF架构~为EF DbContext生成的实体添加注释(T5模板应用)
回到目录 相关文章系列 第八回 EF架构~将数据库注释添加导入到模型实体类中 第二十一回 EF架构~为EF DbContext生成的实体添加注释(T4模板应用) 第二十二回EF架构~为EF DbCo ...
- EF架构~扩展一个分页处理大数据的方法
回到目录 最近总遇到大数据的问题,一次性处理几千万数据不实际,所以,我们需要对大数据进行分块处理,或者叫分页处理,我在EF架构里曾经写过类似的,那是在进行BulkInsert时,对大数据批量插入时候用 ...
随机推荐
- ExtJS入门实例
一.去官网下载EXTJS包extjs5,这里采用的是5.0版本! 二.解压extjs包,找到 ext-all.js基础包(\ext-5.0.0\build): ext-all-debug.js基础包, ...
- 【学习】JAVA的第一天(补)
补上1024第一天的JAVA学习,也刚好是程序员节.今天学习了JAVA的一些历史和基础环境的配置,以及HelloWorld入门程序. JAVA体系:JAVAME(一些简单的移动端开发).JAVAEE( ...
- CodeForces 743C Vladik and fractions (数论)
题意:给定n,求三个不同的数满足,2/n = 1/x + 1/y + 1/z. 析:首先1是没有解的,然后其他解都可以这样来表示 1/n, 1/(n+1), 1/(n*(n+1)),这三个解. 代码如 ...
- MVC4相关Razor语法浅谈
1._LayOut.cshtml 文件为mvc的布局文件,里面包函的是htm的静态文件,作为mvc其他view的基础母版使用,子视图要不想想调用它只需在页面设置@{Layout=null;}即可,现对 ...
- .NET 4.5+项目迁移.NET Core的问题记录
.NET 4.5+项目迁移.NET Core的问题记录 这几天试着把目前的开发框架迁移到新的.net core平台,中间遇到的问题在这里简单记录一下. 迁移过程遇到的最大的问题IOC容器.我目前使用的 ...
- angular下拉
<div class="form-group col-sm-4"> <label class="col-sm-5 control-label" ...
- android TCP 客户端(仅接收数据)
配合log4net使用,用来接收调试信息.因此,此客户端只管通过TCP接收字符串数据,然后显示在界面上. 接收TCP数据 try { Socket s = new Socket("192.1 ...
- [XAF] How to define a business class at runtime or allow end-users to configure its members via the application UI?
How to define a business class at runtime or allow end-users to configure its members via the applic ...
- Alamofire源码学习
Core文件夹: Alamofire.swift - - - 该文件中主要是给用户提供一些便利的调用方法,用户可以直接调用该文件中的便利方法来使用Alamofire相关功能. ...
- Mac OS X双系统变回虚拟机
Mac OS X双系统变回虚拟机 自从装了双系统后,感觉不要太好,装了虚拟机就开始有工作的干劲了.不妙的是,我在Win7系统里并没有装office,用不了word文档就写不了笔记和总结.我不太想在Wi ...