在Linq的MVC应用程序中的IList查询

rit*_*itz 1 linq

我希望下面的类返回IList <>请告诉我它为什么不起作用

public IList<CheckBoxListInfo> GetLinks()
        {
            string linkName = string.Empty;
            int linkId = 0;
            using (var db = new brandconnectionsEntities())
            {
                var query = from s in db.BC_TabTable
                                                 select new
                                                 {

                                                     linkName = s.TabName,
                                                     linkId = s.TabId,
                                                 };

                IList<CheckBoxListInfo> list = query.ToList() as IList<CheckBoxListInfo>;

                return list;

            }
        }
Run Code Online (Sandbox Code Playgroud)

谢谢丽兹

Ada*_*lph 5

您需要更改select语句以返回CheckBoxListInfo对象.

例如

select new CheckBoxListInfo 
{
    LinkName = s.TabName, 
    LinkId = s.TabId, 
}; 
Run Code Online (Sandbox Code Playgroud)

目前它正在返回一个匿名类型.