using System;
using System.Linq;
class P
{
static void Main()
{
var customer = new[]{new
{PKId="001",Name="admin",Pwd="123456",Group="001"},
new
{PKId="002",Name="user",Pwd="user",Group="003"},
new
{PKId="003",Name="geust",Pwd="guest",Group="004"},
new
{PKId="004",Name="aa",Pwd="123456",Group="002"},
new
{PKId="005",Name="bb",Pwd="123456",Group="002"},
new
{PKId="006",Name="cc",Pwd="123456",Group="002"},
};
var groups = new[] { new { PKId = "001",
depict = "最高权限" },
new
{PKId="002",depict="管理员"},
new
{PKId="003",depict="发布信息"},
new
{PKId="004",depict="只有浏览权限"}
};
var data =
from word2 in groups
where word2.depict == "管理员"
select new {
quanxian = word2.depict,
Name =
from word in customer
where word.Group==word.PKId
select word
};
var first = data.First();
Console.WriteLine("{0}, {1}",
first.quanxian, first.Name);
}
}
//下面是输出:
管理员, System.Linq.Enumerable+WhereArrayIterator`1[<>f__AnonymousType0`4[System
.String,System.String,System.String,System.String]]
看到没?Name的值是个其名IEnumerator.
正确的写法应该是:
var data =
from word2 in groups
where word2.depict == &