I am hoping someone can help, my error is
cannot implicitly convert type system.collections.generic.List to xxxlistlitems
I have this
public IDListItems getIDList()
{
IDListItems items = new IDListItem();
try
{
var x = (from c in db.ap_GetIDListItems()
select new IDListItems { CId = c.CID, Id = c.ID }).ToList();
items = x;
}
catch (Exception ex)
{
throw ex;
}
return items;
}
and then I have a class like this
namespace SaSs
{
public class IDListItems
{
public int Id {get; set;}
public string CId { get; set; }
}
}
I think its a issue with my return type but im unsure how to for the type to return a list
Others have suggested changing the type of the variable - I'd recommend removing the variable entirely, along with the pointless catch block. You do need to change the return type as well though:
public List<IDListItems> getIDList()
{
return (from c in db.ap_GetIDListItems()
select new IDListItems { CId = c.CID, Id = c.ID }).ToList();
}
Or without the somewhat pointless query expression:
public List<IDListItems> getIDList()
{
return db.ap_GetIDListItems()
.Select(c => new IDListItems { CId = c.CID, Id = c.ID })
.ToList();
}
See more on this question at Stackoverflow