【发布时间】:2009-09-28 12:24:52
【问题描述】:
背景
目前我有一个使用 RIA 服务的 C# Silverlight 业务应用程序。该应用程序托管在 ASP.NET 中,使用 ADO.NET 实体框架和域服务类来读取和写入 SQL Server 数据库。
场景
我的 DomainServiceClass 中有一个服务器端方法,它返回一个 IEnumerable 对象列表。 在我的 ApplicationName.Web.g.cs 文件中,我也有一个自动生成的函数。 在我的 Silverlight 客户端应用程序中,我希望能够在返回的对象列表上运行 foreach 循环。
DomainServiceClass 方法:
public IEnumerable<Image> GetJobImages(string jobGuid)
{
var query =
(
from j in Context.Job
orderby (j.ShortCode)
where j.JobID.Equals(jobGuid)
join a in Context.Audit //.Distinct()
on j.JobID equals a.Job.JobID
join i in Context.Image
on a.Image.JobID equals i.JobID
select new Image
{
HighResUrl = i.HighResUrl,
LowResUrl = i.LowResUrl,
UploadDate = i.UploadDate
}).AsEnumerable();
return query;
}
ApplicationName.Web.g.cs 自动生成函数:
/// <summary>
/// Returns an EntityQuery for query operation 'GetJobImages'.
/// </summary>
public EntityQuery<Image> GetJobImagesQuery(string jobGuid)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("jobGuid", jobGuid);
return base.CreateQuery<Image>("GetJobImages", parameters, false, true);
}
Silverlight 客户端调用代码:
var context = dds.DomainContext as InmZenDomainContext;
foreach(var item in context.GetJobImagesQuery(currentJob.JobID.ToString())
{
item.etc.....//
}
问题
不幸的是,当我尝试按上述方法调用此方法时,我收到以下错误:
'不能将 System.Windows.Ria.Data.EntityQuery 类型隐式转换为 System.Collections.IEnumerable'。
或
'不包含 GetEnumerator 的公共定义'。
在阅读并与他人交谈后,我被告知我需要更改自动生成函数的返回类型(我认为)。
问题
有谁知道我可以在此 AutoGenerated EntityQuery 上将返回类型更改为 IEnumerable 的方法吗?! - 或者用不同的方式来解决这个问题?
尝试了以下方法:
/// <summary>
/// Returns an EntityQuery for query operation 'GetJobImages'.
/// </summary>
public IEnumerable<Image> GetJobImagesQuery(string jobGuid)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("jobGuid", jobGuid);
return base.CreateQuery<Image>("GetJobImages", parameters, false, true);
}
(由于该方法是自动生成的,因此失败,它只是恢复到我构建解决方案时的状态。)
非常感谢您的帮助。
【问题讨论】:
-
很高兴看到问题的格式如此之好...
标签: c# silverlight entity-framework ienumerable