I have structure like this.
public class ExportStructure
{
public string issueid { get; set; }
public string filename {get;set;}
public bool export { get; set; }
}
public class ExportStructureManager
{
public List<ExportStructure> ExportIntoStructure { get; set; }
public ExportStructureManager()
{
this.ExportIntoStructure = new List<ExportStructure>();
}
public ExportStructure AddToStructure(string issueid,string filename,bool exportornot)
{
ExportStructure expstr = new ExportStructure();
expstr.issueid = issueid;
expstr.filename = filename;
expstr.export = exportornot;
this.ExportIntoStructure.Add(expstr);
return (expstr);
}
public bool GetStatusFromStructure(string issuekey)
{
return (from p in ExportIntoStructure
where p.issueid == issuekey
select p.export));
}
}
From the above one, I want to execute GetStatusFromStructure such that it should return me the export property status. For that one I written like that. But it is giving error as
Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable’ to ‘bool’
at select p.export
How to resolve this?
The problem is that your query is retrieve a sequence of
boolvalues – one for each record matching your filter. Presumably you’re only expecting a single result, so you could useSingle:But you should also consider what you want to happen if there are multiple results or none at all. The options are:
SingleSingleOrDefaultFirstFirstOrDefaultLastLastOrDefaultWhich one is appropriate depends on what you want the behaviour to be in those situations.
You might also want to consider making this a non-query-expression:
Or even match to a single object first, then project: