Dynamic query with extended field

5 posts, 0 answers
  1. Neil Mercer
    Neil Mercer avatar
    18 posts
    Member since:
    Sep 2009

    Posted 03 Mar 2011 Link to this post

    Hi,

    I have a simple database that I have build a database model for using the Visual Designer.  I've extended the model by adding a couple of properties to the partial class of one of the entities.  These properties derive their values from other fields, and in one case from values in a related table.

    Now I'm constructing a dynamic linq query using the Dynamic Linq library included by the Data Services Wizard.  When querying based on one of the database fields, everything is fine.  However if my query is based around one of the extended properties I get and InvalidOperationException when the query runs.  The Exception message is:

    Identifier 'HasReport' is not a parameter or variable or field of 'JTServicesDAL.JTProject'. If 'HasReport' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.

    How can I fix this?  Or alternatively is there a better method to follow?  The aim is to allow the user to construct a query at runtime, and this query should be able to include the extended properties.  I could make them fields in the database, but given they are derived from other fields, would prefer not to do this.

    Thanks,
    Neil.
  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 08 Mar 2011 Link to this post

    Hi Neil Mercer,
     
     This is by design. When a property is used in a LINQ query, OpenAccess needs to know the field to which this property is associated. This is done via the 'FieldAlias' or 'Storage' attribute. It is not possible to use a property without a correponding field in the database, in a LINQ query.
    In order to achieve your aim you could reformulate the query,if possible, in a way that the 'extended property' calculation is pushed to the server, maybe by explicitly specifying it in the query.

    Do get back in case you need further assisstance with this.

    Kind regards,
    Ady
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft banner
  4. Nicolo
    Nicolo avatar
    9 posts
    Member since:
    Aug 2012

    Posted 07 Mar 2012 Link to this post

    Hello
    Ady, is this restriction still there with the latest OpenAccess version?
    Neil Mercer, did you find a solution which allows to use the property directly within Linq?

    Kind regards
    Nicolo
  5. Neil Mercer
    Neil Mercer avatar
    18 posts
    Member since:
    Sep 2009

    Posted 07 Mar 2012 Link to this post

    Hi Nicolo,

    I ended up adding the fields to the database table as computed fields - was more complicated to set up, but then the field was visible and able to be manipulated through OpenAccess.  Only thing I had to make sure to do was make the field read only in the OpenAccess model so that data didn't get pushed back to the database.

    Cheers,
    Neil.
  6. Ady
    Admin
    Ady avatar
    589 posts

    Posted 12 Mar 2012 Link to this post

    Hello Nicolo,

     Yes, at the moment this restriction does still exist, although ,if possible,you could consider the solution Neil has used.

    I am sorry for the inconvenience caused.

    Greetings,
    Ady
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top
DevCraft banner