我正在尝试获取dcs.Agent.AgentAlive (布尔值)的值,但我无法这样做,有人可以建议一下吗?我认为dcs.Agent.AgentAlive在某些情况下是空的。
var dc = (from dcs in DataCollectionStatuses
select new {
dcs.Frequency, ha= dcs.Agent??dcs.Agent
}).FirstOrDefault();使用表达式(dcs.Agent ??)构造或初始化<>f__AnonymousType12 System.String,System.Nullable1System.Int32,DynamicOps.ManagementModel.Agent]类型的实例dcs.Agent)不受支持。
发布于 2014-07-24 02:42:09
你只是想知道代理是否还活着,对吗?如果agent是空的,我假设他不是。那么你只需要非常有用的三元运算符?:
var dc = (from dcs in DataCollectionStatuses
select new {
dcs.Frequency,
IsAgentAlive = dcs.Agent!=null ? dcs.Agent.AgentAlive:false
}
).FirstOrDefault();有关更多信息,请访问http://msdn.microsoft.com/en-us/library/ty67wk28.aspx
https://stackoverflow.com/questions/24907373
复制相似问题