This is a migrated thread and some comments may be shown as answers.

Dynamic query with extended field

5 Answers 268 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Neil Mercer
Top achievements
Rank 1
Neil Mercer asked on 03 Mar 2011, 06:48 AM
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.

5 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 08 Mar 2011, 11:04 AM
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!
0
Nicolo
Top achievements
Rank 1
answered on 07 Mar 2012, 07:37 AM
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
0
Neil Mercer
Top achievements
Rank 1
answered on 08 Mar 2012, 03:49 AM
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.
0
Ady
Telerik team
answered on 12 Mar 2012, 10:17 AM
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 >>
0
Arun
Top achievements
Rank 1
answered on 15 Mar 2018, 08:00 AM
Identifier 'ConfigDataModel' is not a parameter or variable or field of 'MTM.DAL.SMSAlert'. If 'ConfigDataModel' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
Tags
LINQ (LINQ specific questions)
Asked by
Neil Mercer
Top achievements
Rank 1
Answers by
Ady
Telerik team
Nicolo
Top achievements
Rank 1
Neil Mercer
Top achievements
Rank 1
Arun
Top achievements
Rank 1
Share this question
or