Bug Report T290980
Visible to All Users

LINQ-to-XPO throws InvalidOperationException when a query tries to expand a collection property

created 9 years ago

We are exposing XPO via OData 4 under WebApi 2.2 and already have some progress. Can you evaluate the problem with expanding a collection? On any single subentity it works good. It's happening at place showed in attached screenshot. On the left side it is XPCollection<CollectionItemType> and on the right is Boolean which causes wrong conversion.

http://localhost:91/WebApiOData/EntitySet(16)?$expand=CollectionProperty
{
  "error":{
    "code":"",
"message":"The query specified in the URI is not valid. No coercion operator is defined between types 'DevExpress.Xpo.XPCollection`1[CollectionItemType]' and 'System.Boolean'.",
"innererror":{
      "message":"No coercion operator is defined between types 'DevExpress.Xpo.XPCollection`1[CollectionItemType]' and 'System.Boolean'.",
  "type":"System.InvalidOperationException",
  "stacktrace":"
  at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
  at System.Linq.Expressions.Expression.Convert(Expression expression, Type type, MethodInfo method)
  at System.Linq.Expressions.Expression.Convert(Expression expression, Type type)
  at DevExpress.Xpo.XPQueryBase.CreateSubItemCore(Type subType, ExpressionAccessOperator last, CriteriaTypeResolver resolver, ParameterExpression row, Int32& rowIndex)
  at DevExpress.Xpo.XPQueryBase.CreateSubItemCore(Type subType, ExpressionAccessOperator last, CriteriaTypeResolver resolver, ParameterExpression row, Int32& rowIndex)
  at DevExpress.Xpo.XPQueryBase.CreateSubItemCore(Type subType, ExpressionAccessOperator last, CriteriaTypeResolver resolver, ParameterExpression row, Int32& rowIndex)
  at DevExpress.Xpo.XPQueryBase.CreateSubItemCore(Type subType, MemberInitOperator last, CriteriaTypeResolver resolver, ParameterExpression row, Int32& rowIndex)
  at DevExpress.Xpo.XPQueryBase.CreateSubItemCore(Type subType, MemberInitOperator last, CriteriaTypeResolver resolver, ParameterExpression row, Int32& rowIndex)
  at DevExpress.Xpo.XPQueryBase.CreateItemCore(Type type, MemberInitOperator last)
  at DevExpress.Xpo.XPQueryBase.GetData(Type type)
  at DevExpress.Xpo.XPQueryBase.Enumerate(Type type)
  at DevExpress.Xpo.XPQuery`1.GetEnumerator()
  at DevExpress.Xpo.XPQuery`1.System.Collections.IEnumerable.GetEnumerator()
  at System.Web.OData.EnableQueryAttribute.SingleOrDefault(IQueryable queryable, HttpActionDescriptor actionDescriptor)
  at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)
   at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
    }
  }
}

Show previous comments (3)
DevExpress Support Team 9 years ago

    Thank you for the sample. We need some time to research it. I will get back once we have any result.

    DevExpress Support Team 9 years ago

      We have researched this issue and come to the conclusion that it is a bug in our code. We will try to fix it as soon as we can. I'm afraid there's no simple workaround at the moment.

      OI OI
      Oleksandr Ieremenko 9 years ago

        Ok, thanks! Do you know why $select doesn't work with an entity/collection?

        Answers approved by DevExpress Support

        created 9 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.