我有和现有数据库有3个表和它们之间的关系。其中两个表具有名为“Id”的主键列,它们是整数列。第三个表有一个复合主键,它由与其他两个表(链接表或多对多表)相关的外键组成。
我设置了新的Azure移动服务,并将此数据库指定为服务数据的来源。我为.NET中的服务构建了控制器,模型和数据对象(DTO)。一切看起来都正确,但当我尝试从任何表中请求数据时,我收到此错误:
{
message: "The query specified in the URI is not valid. Property 'Id' is of an unrecognized EdmPropertyKind."
exceptionMessage: "Property 'Id' is of an unrecognized EdmPropertyKind."
exceptionType: "Microsoft.Data.OData.ODataException"
stackTrace: " at Microsoft.Data.OData.Query.SyntacticAst.SelectPathSegmentTokenBinder.TryBindAsDeclaredProperty(PathSegmentToken tokenIn, IEdmEntityType entityType, ODataPathSegment& segment) at Microsoft.Data.OData.Query.SyntacticAst.SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(PathSegmentToken tokenIn, IEdmModel model, IEdmEntityType entityType) at Microsoft.Data.OData.Query.SyntacticAst.SelectPropertyVisitor.ProcessTokenAsPath(NonSystemToken tokenIn) at Microsoft.Data.OData.Query.SyntacticAst.SelectPropertyVisitor.Visit(NonSystemToken tokenIn) at Microsoft.Data.OData.Query.SyntacticAst.NonSystemToken.Accept(IPathSegmentTokenVisitor visitor) at Microsoft.Data.OData.Query.SyntacticAst.SelectBinder.Bind(SelectToken tokenIn) at Microsoft.Data.OData.Query.SelectExpandSemanticBinder.Parse(IEdmEntityType elementType, IEdmEntitySet entitySet, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration) at Microsoft.Data.OData.Query.ODataUriParser.ParseSelectAndExpandImplementation(String select, String expand, IEdmEntityType elementType, IEdmEntitySet entitySet) at System.Web.Http.OData.Query.SelectExpandQueryOption.get_SelectExpandClause() at System.Web.Http.OData.Query.Validators.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings) at System.Web.Http.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings) at System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings) at System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings) at System.Web.Http.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions) at System.Web.Http.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor) at System.Web.Http.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
}
有谁知道我做错了什么?
答案 0 :(得分:3)
要从Azure Mobile Services访问数据库,每个表必须符合以下要求:
- 该表必须位于您的移动服务架构中(架构是您的移动服务的名称)
- 该表必须具有名为“id”的标识列,并且必须全部为小写字母
所以听起来你需要i)确保将具有id
主键的2个表设置为标识字段,并且ii)添加id
主键(这是一个标识)到您的第3个表,您可以在使用中基本忽略,但将使Azure Mobile Services可以接受。您还可以为旧主键创建索引以实现性能目的。
我建议您查看this blog post。