我有一个 DataTable 我想将其转换为列表
var rows = cableDataTable.AsEnumerable()
.Select((x) =>
new
{
TagGroup = x.Field<string>("TagNo"),
RowNo = (i == 0) ? (j++).ToString() : "",
TagNo = x.Field<string>("TagNo"),
FromBayPanel = x.Field<string>("FromBayPanel"),
Size = x.Field<string>("CoreSize"),
Type = x.Field<string>("Type"),
FromBay = x.Field<string>("FromBay"),
FromPanel = x.Field<string>("FromPanel"),
CoreNo = x.Field<string>("CoreNo") == DBNull.Value.ToString() ? "" : x.Field<string>("CoreNo"),
RealCoreNo = x.Field<int>("RealCoreNo"),
FromDevice = x.Field<string>("FromDevice") == DBNull.Value.ToString() ? "" : x.Field<string>("FromDevice"),
FromTerminal = x.Field<string>("FromTerminal") == DBNull.Value.ToString() ? "" : x.Field<string>("FromTerminal"),
FromRef = x.Field<string>("FromRef") == DBNull.Value.ToString() ? "" : x.Field<string>("FromRef"),
ToBay = x.Field<string>("ToBay"),
ToPanel = x.Field<string>("ToPanel"),
ToDevice = x.Field<string>("ToDevice") == DBNull.Value.ToString() ? "" : x.Field<string>("ToDevice"),
ToTerminal = x.Field<string>("ToTerminal") == DBNull.Value.ToString() ? "" : x.Field<string>("ToTerminal"),
ToRef = x.Field<string>("ToRef") == DBNull.Value.ToString() ? "" : x.Field<string>("ToRef"),
Remark = x.Field<string>("Remark") == DBNull.Value.ToString() ? "" : x.Field<string>("Remark"),
}).ToList();
我想必须对多个列上的 DataTable 进行分组。但是当我这样做时
1)我该怎么做?
2) 还有一个问题是在 SQL Server 端(通过 isNull 命令)还是客户端转换 DBNull 值更好?