我在EDMX的CSDL中定义了以下函数。
<Function Name="GetSprintDuration" ReturnType="Edm.Decimal">
<Parameter Name="sprintId" Type="Edm.Int32" />
<DefiningExpression>
SUM( SELECT VALUE h.Duration
FROM ApplicationEntities.Hours as h
WHERE h.Story.Project.SprintId = sprintId)
</DefiningExpression>
</Function>
我访问该功能的代码如下:
[EdmFunction("ApplicationModel", "GetSprintDuration")]
public decimal? GetSprintDuration(int sprintId)
{
return this.QueryProvider.Execute<decimal?>(Expression.Call(
Expression.Constant(this),
(MethodInfo)MethodInfo.GetCurrentMethod(),
Expression.Constant(sprintId, typeof(int))));
}
当我调用此方法时,我收到以下错误:
'SprintId'不是类型的成员 'ApplicationModel.Project'中 当前加载的模式。
调用QueryProvider.Execute时会生成错误:
Line 17: public decimal? GetSprintDuration(int sprintId)
Line 18: {
Line 19: return this.QueryProvider.Execute<decimal?>(Expression.Call(
Line 20: Expression.Constant(this),
Line 21: (MethodInfo)MethodInfo.GetCurrentMethod(),
如果我将功能更改为:
<Function Name="GetSprintDuration" ReturnType="Edm.Decimal">
<Parameter Name="sprintId" Type="Edm.Int32" />
<DefiningExpression>
SUM( SELECT VALUE h.Duration
FROM ApplicationEntities.Hours as h
WHERE h.HourId != 0)
</DefiningExpression>
</Function>
我的应用程序正常运行......出于某种原因,我无法访问完整的实体模型。有没有办法让它可以访问完整的实体模型或者这是不可能的?
提前致谢!
答案 0 :(得分:1)
在 @Henk Holterman 的帮助下,我能够解决我的问题...我没有意识到ESQL支持JOINS,所以这是工作代码的样子:
<Function Name="GetSprintDuration" ReturnType="Edm.Decimal">
<Parameter Name="sprintId" Type="Edm.Int32" />
<DefiningExpression>
SUM( SELECT VALUE h.Duration
FROM ApplicationEntities.Hours as h
JOIN ApplicationEntities.Stories as s on h.StoryId == s.StoryId
WHERE s.SprintId == sprintId )
</DefiningExpression>
</Function>