var users = from user in st.Users
where user.UDID == cr.User.Udid
select user;
var cityIds from city in users.First().Cities
select city.ID;
DoSomethingWith(cityIds);
它始于此查询:
select CityID from UserCities inner join User on User.ID=UserID where User.UDID=@UDID;
我似乎无法使用Linq-to-Entities
获得正确的连接语法答案 0 :(得分:6)
使用查询表达式并不能真正帮到你,你不需要其中两个。这是一个直接的翻译:
var cityIds = st.Users
.Where(user => user.UDID == cr.User.Udid)
.First()
.Cities
.Select(city => city.ID);
现在使用First
可以获取谓词的事实,您可以删除Where
:
var cityIds = st.Users
.First(user => user.UDID == cr.User.Udid)
.Cities
.Select(city => city.ID);
答案 1 :(得分:1)
我想出了我想要实现的目标。
var cityIds = from city in st.Users.First(x => x.UDID == cr.User.Udid).Cities
select city.ID