我有两个数据表
var userList1 = from myRow in dt.AsEnumerable()
where myRow.Field<bool?>("IsActive1") == null ? true : myRow.Field<bool?>("IsActive1") == true
select myRow;
var userList2 = from myRow in dt1.AsEnumerable()
select myRow;
dt1表显示如下:
但我想从此Linq查询中获取空的UserId的docCount,
var objUserSetUp1 = (from A in userList1
join B in userList2 on new { UserId = A.Field<Int64?>("Id") == null ? 0 : A.Field<Int64>("Id") } equals new { UserId = B.Field<Int64?>("UserId") == null ? 0 : B.Field<Int64>("UserId") }
select new
{
UserId = A.Field<Int64>("Id"),
FirstName = A.Field<string>("FirstName"),
SurName = A.Field<string>("SurName"),
Computer_Name = A.Field<string>("Computer_Name"),
IP_Address = A.Field<string>("IP_Address"),
LogInTime = A.Field<string>("LogInTime") == null ? "UnKnown" : A.Field<string>("LogInTime"),
UserName = A.Field<string>("UserName"),
Password = A.Field<string>("Password"),
login_Id = A.Field<Int64?>("login_Id") == null ? 0 : A.Field<Int64?>("login_Id"),
docCount = B.Field<Int64>("docCount")
}).ToList();
但是它抛出错误。“值不能为空。” 如何在objUserSetUp1中获取空的UserId docCount并避免在objUserSetUp1对象中发生此异常?
您是否需要所有UserId不为null的计数?像这样?
var objUserSetUp1 = (from A in userList1
where A.Field<Int64>("Id") != null
select new
{
UserId = A.Field<Int64>("Id"),
FirstName = A.Field<string>("FirstName"),
SurName = A.Field<string>("SurName"),
Computer_Name = A.Field<string>("Computer_Name"),
IP_Address = A.Field<string>("IP_Address"),
LogInTime = A.Field<string>("LogInTime") == null ? "UnKnown" : A.Field<string>("LogInTime"),
UserName = A.Field<string>("UserName"),
Password = A.Field<string>("Password"),
login_Id = A.Field<Int64?>("login_Id") == null ? 0 : A.Field<Int64?>("login_Id"),
docCount = A.Field<Int64>("docCount")
}).ToList();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句