Table<east_member> member = dataContext.GetTable<east_member>();
var data = from dataObj in member
where dataObj.member_about2id == "21a2a5be-295a-440d-a2c7-b01f8dcb2b50"
orderby dataObj.member_order
select new { dataObj.east_about2.about2_cname, dataObj.member_cname, dataObj.member_cduty };
foreach (east_member m in data)
{
Response.Write(m.member_cname);
}
foreach 提示:无法将类型 "AnonymousType#1" 转换为 "LinqClass.east_member".
经测试,将
select new { dataObj.east_about2.about2_cname, dataObj.member_cname, dataObj.member_cduty };
改成 select dataObj 就正常了,我看书上就是这样筛选显示项.
请各位大是指点一二.
------解决方案--------------------------------------------------------
select new {……}//一个匿名类
你可以将foreach (east_member m in data)
改为
foreach (var m in data)
------解决方案--------------------------------------------------------
也可以select new 自定义
var data = from dataObj in member
where dataObj.member_about2id == "21a2a5be-295a-440d-a2c7-b01f8dcb2b50"
orderby dataObj.member_order
select new east_member() { dataObj.east_about2.about2_cname, dataObj.member_cname, dataObj.member_cduty };
------解决方案--------------------------------------------------------
foreach (east_member m in data)
{
Response.Write(m.member_cname);
}
少了一个类型推断的var
foreach ( var m in data)
{
Response.Write(m.member_cname);
}
------解决方案--------------------------------------------------------
一个是匿名类 一个不是