Silverlight DomainService 未从 include() 返回信息
我的 RIA DomainService 中有两个查询。一种是使用 linq 的简单 get,另一种是使用 peramiter 和 linq join 的 get。使用 include() 时的简单获取将我想要的数据返回到我的 silverlight 数据网格。带有 join 的则没有,为什么?
这是我的两种方法。最上面的那个是有效的。
public IQueryable<UserProfile> GetUserProfiles()
{
// GetUserProfiles order by sum of carma
return from up in ObjectContext.UserProfiles.Include("PriceRange")
where up.Active
orderby up.SumKarma descending
select up;
}
public IQueryable<UserProfile> GetUserProfilesByCountyID(int searchCountyID)
{
return from up in ObjectContext.UserProfiles.Include("PriceRange")
join upsc in ObjectContext.UserProfileSearchCounties on up.IDUserProfile equals upsc.IDUserProfile
where up.Active && upsc.IDSearchCounty == searchCountyID
orderby up.SumKarma descending
select up;
}
更新:根据 Cubicle.Jockey 的评论,我能够解决这个问题。下面是我最终使用的。
public IEnumerable<UserProfileSearchCounty> GetUserProfilesByCountyID(int searchCountyID)
{
return (from upsc in ObjectContext.UserProfileSearchCounties.Include("UserProfile").Include("UserProfile.PriceRange")
where upsc.UserProfile.Active && upsc.IDSearchCounty == searchCountyID
orderby upsc.UserProfile.SumKarma descending
select upsc).ToList();
}
I have two queries in my RIA DomainService. one is a simple get using linq and the other is a get with a peramiter and a linq join. the simple get when using include() returns the data i want to my silverlight datagrid. the one with the join does not, why?
here are my two methods. the top one is the one that works.
public IQueryable<UserProfile> GetUserProfiles()
{
// GetUserProfiles order by sum of carma
return from up in ObjectContext.UserProfiles.Include("PriceRange")
where up.Active
orderby up.SumKarma descending
select up;
}
public IQueryable<UserProfile> GetUserProfilesByCountyID(int searchCountyID)
{
return from up in ObjectContext.UserProfiles.Include("PriceRange")
join upsc in ObjectContext.UserProfileSearchCounties on up.IDUserProfile equals upsc.IDUserProfile
where up.Active && upsc.IDSearchCounty == searchCountyID
orderby up.SumKarma descending
select up;
}
UPDATE: with comment from Cubicle.Jockey i was able to work through this. below is what i ended up using.
public IEnumerable<UserProfileSearchCounty> GetUserProfilesByCountyID(int searchCountyID)
{
return (from upsc in ObjectContext.UserProfileSearchCounties.Include("UserProfile").Include("UserProfile.PriceRange")
where upsc.UserProfile.Active && upsc.IDSearchCounty == searchCountyID
orderby upsc.UserProfile.SumKarma descending
select upsc).ToList();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会返回所有数据,因为您正在执行选择,这只是 UserProfile 而不是您正在执行的联接查询。
All the data is not being returned because you are doing a select on up which is just UserProfile and not the joined query you were performing.