如何将查询结果转换类型?
表中有字段:ID、userName、password,只想获取ID和userName字段组成的新表:
C# code
public IQueryable<User> getListByName(string name)
{
Table<User> user = dc.GetTable<User>();
var query = from temp in user
where temp.userName == name
select new{temp.ID,temp.userName };//如果此行为select temp;然后return query查询正常
return query; //不修改有如下图片提示
}
------解决方案--------------------不返回匿名,重新构建User实体
select new User{ID=temp.ID,UserName=temp.userName };
------解决方案--------------------10楼说的是有道理的
public IQueryable<User> getListByName(string name)
{
Table<User> user = dc.GetTable<User>();
var query = from temp in user
where temp.userName == name
select new User{ID=temp.ID,userName=temp.userName };
return query;
}