Field obviously exists, use this field to query error with Web API?

I am a Microsoft Dynamics 365 & Power Platform aspects engineer Rayong, Microsoft Most Valuable Professional is the July 2015 to June 2018 for three consecutive years Dynamics CRM / Business Solutions aspects (Microsoft MVP), I welcome the attention of the public micro-channel number MSFTDynamics365erLuoYong, or 20,190,923 reply 369 may facilitate access to this article, but you can get the latest information I Bowen issued in the first room, follow me!

Today I test, Dynamics 365 Customer Engagement V9.X version of this problem does not exist, for V8.X still there, I've seen at least two cases.

I am here to give an example of encounter, some people build fields to the entity when the field names and the name of the same entity. For example, I tested here a logical name of the entity called ly_test.

 

 

I built a field, also called the logical name ly_test.

 

 

Then I used the Web API to display the first record, also see the field.

 

Then I use this field to construct the query to see, for example, $ filter = ly_test eq null, you can see V9.X version of Dynamics 365 Customer Engagement is no longer being given.

 

 But if it is V8.X will complain:

{
  "error":{
    "code":"","message":"Could not find a property named 'ly_test' on type 'Microsoft.Dynamics.CRM.ly_test'.","innererror":{
      "message":"Could not find a property named 'ly_test' on type 'Microsoft.Dynamics.CRM.ly_test'.","type":"Microsoft.OData.Core.ODataException","stacktrace":"   \u5728 Microsoft.OData.Core.UriParser.Parsers.EndPathBinder.GeneratePropertyAccessQueryForOpenType(EndPathToken endPathToken, SingleValueNode parentNode)\r\n   \u5728 Microsoft.OData.Core.UriParser.Parsers.EndPathBinder.BindEndPath(EndPathToken endPathToken)\r\n   \u5728 Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)\r\n   \u5728 Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)\r\n   \u5728 Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   \u5728 Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)\r\n   \u5728 Microsoft.OData.Core.UriParser.Parsers.FilterBinder.BindFilter(QueryToken filter)\r\n   \u5728 Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, IEdmType elementType, IEdmNavigationSource navigationSource)\r\n   \u5728 Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseFilter()\r\n   \u5728 System.Web.OData.Query.FilterQueryOption.get_FilterClause()\r\n   \u5728 Microsoft.Crm.Extensibility.OData.DataQueryOptionsConverter.SetFilterExpression(QueryExpression qe, FilterQueryOption filterQueryOption)\r\n   \u5728 Microsoft.Crm.Extensibility.OData.QueryOptionsConverterBase`4.GetQueryExpression(ODataQueryOptions queryOptions, String edmEntityName, CrmODataExecutionContext context)\r\n   \u5728 Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, String castedEntityName, ODataQueryOptions queryOptions)\r\n   \u5728 Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n   \u5728 Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n   \u5728 lambda_method(Closure , Object , Object[] )\r\n   \u5728 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   \u5728 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- \u5f15\u53d1\u5f02\u5e38\u7684\u4e0a\u4e00\u4f4d\u7f6e\u4e2d\u5806\u6808\u8ddf\u8e2a\u7684\u672b\u5c3e ---\r\n   \u5728 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   \u5728 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   \u5728 System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- \u5f15\u53d1\u5f02\u5e38\u7684\u4e0a\u4e00\u4f4d\u7f6e\u4e2d\u5806\u6808\u8ddf\u8e2a\u7684\u672b\u5c3e ---\r\n   \u5728 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   \u5728 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   \u5728 System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- \u5f15\u53d1\u5f02\u5e38\u7684\u4e0a\u4e00\u4f4d\u7f6e\u4e2d\u5806\u6808\u8ddf\u8e2a\u7684\u672b\u5c3e ---\r\n   \u5728 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   \u5728 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   \u5728 System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
  }
}

 

你会问怎么办?其实很简单,你不用这个字段做筛选条件看下第一条就知道,原来返回的时候自动为这个与实体逻辑名称相同的字段加了一个1,也就是会变成 ly_test1,那么你做筛选的时候就要改一下名字,用 ly_test1,这样就不会有问题了。

当然如果你的系统升级的话,比如从V8.X升级到V9.X就会掉这个坑里了,V9.X已经可以了,不会自动在后面加1了,你代码不改话,使用Web API获取或者查询使用该字段就会报错。

所以我这里的忠告是,字段的名称不要和实体的名称相同!

Guess you like

Origin www.cnblogs.com/luoyong0201/p/Dynamics_365_Do_Not_Set_Field_Name_Same_As_Entity_Name.html