Open DigitalPlatform opened 4 years ago
var opers = context.CircuOpers
.Where(b => (strLibraryCode == "*" || b.LibraryCode == strLibraryCode)
&& string.Compare(b.Date, strStartDate) >= 0
&& string.Compare(b.Date, strEndDate) <= 0)
.Join(
context.Patrons,
oper => oper.ReaderBarcode,
patron => patron.Barcode,
(oper, patron) => new
{
Department = patron.Department,
BorrowCount = oper.Action == "borrow" ? 1 : 0,
ReturnCount = oper.Action == "return" ? 1 : 0
}
)
.GroupBy(x => x.Department)
.Select(g => new
{
Department = g.Key,
BorrowCount = g.Sum(t => t.BorrowCount),
ReturnCount = g.Sum(t => t.ReturnCount)
})
.OrderByDescending(t => t.BorrowCount).ThenBy(t => t.Department)
.ToList();
注意上面的 GroupBy 后面必须跟上 Select,而且 Select 中应该是一个 key 加上若干个 Sum 列。如果不满足这个条件,就会抛出异常(然后只能在 GroupBy 前面加上一个 AsEnumberable() (转换为 Client 端 LINQ)才行了),但 Client 端 LINQ 对资源消耗很大。
参考文献:
https://github.com/dotnet/efcore/issues/18102 https://github.com/dotnet/efcore/issues/17068
https://docs.microsoft.com/en-us/ef/core/saving/basic
https://entityframeworkcore.com/zh-CN/knowledge-base/55766322/
https://www.connectionstrings.com/mysql/
Keep TCP Sockets alive
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Keepalive=10;
Number of seconds between each keep-alive package send.
https://www.entityframeworktutorial.net/entityframework6/transaction-in-entity-framework.aspx
https://www.red-gate.com/simple-talk/dotnet/net-framework/catching-bad-data-in-entity-framework/
https://www.codeproject.com/Articles/1164269/LINQ-to-Entities-Cross-Apply-and-Left-Outer-Join
新版报表模块试图解决 dp2library 服务器端无法生成报表的问题。
新版函数库可以被 dp2library.exe 调用,也可以被前端调用。