Is this is a proper use of IEnumerable or shell I use List?
what do I need to put in <PropertyInfo>?
public static IEnumerable<PropertyInfo> GetNewsList<T>(int FID)
{
CatomWebNetDataContext pg = (CatomWebNetDataContext)db.GetDb();
return (from nls in pg.NewsCat_ITEMs
join vi in pg.VIRTUAL_ITEMs on nls.NC_VI_ID equals vi.VI_ID
where vi.VI_VF_ID == FID
select new { nls, vi });
}
or
public List<PropertyInfo> GetPublic<T>(int FID)
{
CatomWebNetDataContext pg = (CatomWebNetDataContext)db.GetDb();
var nl = (from nls in pg.NewsCat_ITEMs
join vi in pg.VIRTUAL_ITEMs on nls.NC_VI_ID equals vi.VI_ID
where vi.VI_VF_ID == FID
select new { nls, vi });
List<PropertyInfo> retList = new List<PropertyInfo>();
foreach (var item in nl)
{
retList.Add(item);
}
return retList;
}
The list is an instace of type, that implements IEnumerable. What it means? That if you want to return the
IEnumerable<PropertyInfo>you have to create a list (or array etc.) of it and then return it.. From the outside of the method it will look like you are returningIEnumerable<PropertyInfo>but really it will be aList<PropertyInfo>.About your query… You have to select object of type
PropertyInfo, but right now you ae returning some anonymouse type. You should try it like this: