我正在获取一个数据表并将其序列化为geojson。我为此使用linq:
var envelope = new
{
type = "FeatureCollection",features = dataTable.AsEnumerable().Select(record => new {
type = "Feature",properties = new
{
Name = Convert.ToString(record["Name"]),Date = Convert.ToString(record["Date"]),Icon = Convert.ToString(record["imageUrl"]),//ReportMonth = Convert.ToString(record["Month"]),ReportMonth = (!string.IsnullOrEmpty(record["Month"])) ? Convert.ToString(record["ReportMonth"]) : string.Empty
},geometry = new
{
type = "Point",coordinates = new[] {
Convert.ToDecimal(record["Lon"]),Convert.ToDecimal(record["Lat"])
}
}
}).ToArray()
};
当数据表具有所有列时,此方法有效。如果数据表中不存在该列(即列Month
),则迭代失败。
是否可以检查该列是否存在?我尝试使用三元运算符检查该值,但是由于我仍在检查该值是否存在,因此它显然不起作用。