c# - 如何在 linq 的连接条件中使用两个 substring() 方法
问题描述
我正在实施 asp.net 核心项目。我有如下查询:
var numerator = from t1 in _context.Apiapplicant
join t2 in _context.ApiApplicantHistory on t1.Id equals t2.ApiApplicantId
join t3 in _context.EntityType on t2.LastReqStatus equals t3.Id
join t4 in mytotal on new { t2.Date.Substring(0,4), t2.Date.Substring(2,5) } equals new { t4.Year, t4.Month }
……
我的问题是,在最后一行我想在给定条件下加入 mytotal,但是表达式 t2.Date.Substring(0,4), t2.Date.Substring(2,5) } 等于 new { t4.Year , t4.Month } ... 出现错误。如果有人告诉我如何写这样的条件,我将不胜感激。
解决方案
当你调用一个方法来创建匿名对象的成员时,你需要将它分配给成员名称,否则会报错:
无效的匿名类型成员声明符。匿名类型成员必须使用成员分配、简单名称或成员访问来声明。
将最后一行更改为:
join t4 in mytotal on new { Year = t2.Date.Substring(0,4), Month = t2.Date.Substring(2,5) } equals new { t4.Year, t4.Month }
我希望你觉得这有帮助。
推荐阅读
- flutter - 使用 Flutter 连接到 Yahoo Finance API
- typescript - `unknown` 类型被强制转换为 `string`,尽管 `unknown` 有官方语义
- react-native - 使用本机反应更改firebase中的密码
- php - 当我单击提交按钮时,如何阻止表单验证代码重复(php ajax jquery html)
- postgresql - 在 Postgres 中安全删除用户
- python - GitHub:发布生成的 HTML 报告
- java - 如何从 StringBuilder 中删除重复项?
- python-3.x - Python VTK 旋转使渲染窗口挂起
- c++ - c++ - 让函数将单独函数的信息输出到文本文件
- jquery - 图表 js v3 如何格式化工具提示