当我尝试在任何导航属性上使用 Expand 时,出现以下异常。
$id: "1",
$type: "System.Web.Http.HttpError, System.Web.Http",
Message: "An error has occurred.",
ExceptionMessage: "'object' does not contain a definition for 'Include'",
ExceptionType: "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException",
StackTrace: " at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
如果我将包含在 Breeze 控制器中,一切正常。如果我不这样做并且只是在客户端上使用扩展,我会收到该错误。任何帮助是极大的赞赏!
这是用于尝试检索数据的 URL
/breeze/maxsys/CallOutcomes?$expand=CallOutcomeAction
这是模型
[Table("CallOutcomes")]
public class CallOutcome {
[Key]
public int Id { get; set; }
[Required]
public string Description { get; set; }
public bool IsInternal { get; set; }
public int CallOutcomeActionId { get; set; }
[ForeignKey("CallOutcomeActionId")]
[InverseProperty("CallOutcomes")]
public CallOutcomeAction CallOutcomeAction { get; set; }
public ICollection<CallOutcomeHistory> CallOutcomeHistories { get; set; }
}
控制器如下所示(我删除了其他一些 get 方法)
[BreezeController]
[Authorize]
[RequireHttps]
public class MaxsysController : ApiController
protected IMaxsysBreezeRepository Repository { get; set; }
public MaxsysController(IMaxsysBreezeRepository repository)
{
Repository = repository;
}
[HttpGet]
public IQueryable<CallOutcome> CallOutcomes()
{
return Repository.CallOutcomes;
}
}
错误来自 BreezeQueryableAttribute.cs 中的此方法
public virtual IQueryable ApplyExpand(IQueryable queryable, string expandsQueryString, HttpRequestMessage request)
{
(from s in expandsQueryString.Split(new char[] { ',' }) select s.Trim()).ToList<string>().ForEach(delegate (string expand) {
queryable = (IQueryable) ((dynamic) queryable).Include(expand.Replace('/', '.'));
});
return queryable;
}
参数值为
queryable = {SELECT
[Extent1].[Id] AS [Id],
N'b1d28373-98a2-4a88-9733-7872acd28bd2' AS [C1],
[Extent1].[Description] AS [Description],
[Extent1].[IsInternal] AS [IsInternal],
[Extent1].[CallOutcomeActionId] AS [CallOutcomeActionId],
N'CallOutcomeAction' AS [C2],
N'b1d28373-98a2-4a88-9733-7872acd28bd2' AS [C3],
[Extent2].[Id] AS [Id1],
[Extent2].[Description] AS [Description1]
FROM [dbo].[CallOutcomes] AS [Extent1]
INNER JOIN [dbo].[CallOutcomeActions] AS [Extent2] ON [Extent1].[CallOutcomeActionId] = [Extent2].[Id]}
expandsQueryString = "CallOutcomeAction"
HttpRequestMessage ={Method: GET, RequestUri: 'http://127.0.0.1:82/breeze/maxsys/CallOutcomes?$expand=CallOutcomeAction', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: keep-alive
Accept: text/html
Accept: application/xhtml+xml
Accept: application/xml; q=0.9
Accept: */*; q=0.8
Accept-Encoding: gzip
Accept-Encoding: deflate
Accept-Encoding: sdch
Accept-Language: en-US
Accept-Language: en; q=0.8
Host: 127.0.0.1:81
User-Agent: Mozilla/5.0
User-Agent: (Windows NT 6.1; WOW64)
User-Agent: AppleWebKit/537.36
User-Agent: (KHTML, like Gecko)
User-Agent: Chrome/27.0.1453.94
User-Agent: Safari/537.36
}}