c# - 无法从列中检索具有空值的数据
问题描述
我有如下数据。
AccountNo, PaymentCode, Priority
NULL, 01, 99
NULL, 01, 99
0711712916, 03, 99
0711712916, 03, 99
我想获取上面的所有数据,我尝试使用下面的代码
var prioritasPembayarans = db.VWPrioritasPembayarans.Where(x => arrValidPaymentCodes.Contains(x.PaymentCode))
.OrderBy(x => x.AccountNo)
.ThenBy(x => x.Priority)
.ToList();
班级
public class VWPrioritasPembayaran
{
[Key, Column(Order = 0)]
public string AccountNo { get; set; }
[Key, Column(Order = 1)]
public string PaymentCode { get; set; }
public byte Priority { get; set; }
public decimal EndingBalance { get; set; }
public decimal TotalTransfer { get; set; }
}
当我调试时,我得到 4 个数据, . 在第三个和第四个数据中,我可以展开并查看数据,但在第一个和第二个数据中,我得到一个空值。我想问的是如何获取第三个和第四个数据之类的数据,即使AccountNo 列为空。谢谢
解决方案
一个技巧可以是 -
var prioritasPembayarans = db.VWPrioritasPembayarans.Where(x => arrValidPaymentCodes.Contains(x.PaymentCode))
.OrderBy(x => x.AccountNo != null ? x.AccountNo : "")
.ThenBy(x => x.Priority)
.ToList();
推荐阅读
- html - 需要在动态循环进度条中单独更新值
- firebase - String id = db.collection("myCollection").document().getId() 如何在不访问 Firestore 数据库的情况下提供文档 ID?
- sql - 无法在 sql 中编辑二进制行的值
- ag-grid - ag grid react:我们可以同时拥有客户端和服务器端过滤器吗?
- python - 删除原始代码后我可以关闭 Flask 服务器吗?
- bash - 获取 shell 脚本中正在运行的 docker 容器的名称
- python - django中的配置文件模型不保存新更新
- discord - 如何在指定时间为用户添加角色?
- java - 自动创建队列、交换和绑定 - 使用 qpid Embedded Broker 进行集成测试 - 在 JSON 文件配置中
- mysql - 如何使用 Prometheus 查询不同的 mySQL 数据库进行业务监控