0

我收到错误

不能隐式转换类型“int?” 到'system.collections.generic.list?

有人可以帮我吗?

internal class PatchDetails
{
    internal List<int> ServerID { get; set; }
    internal List<string> PatchStatus { get; set; }
}
class Program
{        
    void PatchQueue()
    {
        List<PatchDetails> patchinfo = new List<PatchDetails>();            
        using (PatchEntities server = new PatchEntities())
        {
            patchinfo = (from patches in server.AppPM_Patches
                         where patches.PatchStatus == "Started" 
                         || patches.PatchStatus == "NotStarted"
                         select new PatchDetails { ServerID = patches.ServerId, PatchStatus = patches.PatchStatus }).ToList();
        }
    }
}       
4

2 回答 2

2

您将 aint和 astring放入对象中,因此我认为您希望每个PatchDetails都包含这些,而不是它们的列表:

internal class PatchDetails
{
  internal int? ServerID { get; set; }
  internal string PatchStatus { get; set; }
}

如果您不希望该ServerID属性可以为空,则从int?查询中获取值:

ServerID = patches.ServerId.Value
于 2012-09-28T11:40:42.943 回答
0

select 语句返回单个 PatchDetails 对象,您尝试将单个类强制转换为不正确的列表。

如果您尝试获取单个对象,则可以删除 .ToList()。

于 2012-09-28T11:40:12.350 回答