This is a migrated thread and some comments may be shown as answers.
Obtain IQueryable for select all from artificial type
7 Answers 97 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Krasimir
Top achievements
Rank 1
Krasimir asked on 11 Oct 2010, 08:02 AM
Hi

I was trying to select all elements from artificial type having a class name specified at runtime.
Usually I compose a OQL  query "select * ClassExtent" and work with returned IQuery interface (Probably there are better type safe ways to obtain same functionality so any hint here will be highly appreciated ).

However for dynamic filter creation I need to combine several conditions and approach I have taken (based on filtering with dynamic controls System.Web.DynamicData) require select all operation to be returned as IQueryable (or IEnumerable ) so it can be combined with filter logic

Could you advice me how can achieve select all elements from artificial type at runtime (having class name ) as IQueryable?

Best regards
Krasimir Filipov

7 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 14 Oct 2010, 09:25 AM
Hello Krasimir,

Sorry for the delayed reply.
In fact this is a new feature in the product. It is part of the latest internal build of Telerik OpenAccess ORM with version 2010.2.1013.8.
In order to achieve this you should use the FieldValue method to access the value of the artificial field:

IQueryable result = scope.Extent<ClassName>().Where(p => p.FieldValue<FieldType>(FieldName) == CompareValue);

Hope that helps.

Greetings,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Krasimir
Top achievements
Rank 1
answered on 18 Oct 2010, 07:57 AM
public Type GetArtificialType(string typeName)
       {
           string fullName = GetArtificialFullTypeName(typeName);
           //TODO find less expensive way of detecting type names - like cached artificial assembly name
           IPersistentTypeDescriptor ptd = scope.PersistentMetaData.GetPersistentTypeDescriptor(fullName);
           Object sampleInstance = ptd.CreateInstance(null);
           return sampleInstance.GetType();
       }
 
 
   public IQueryable GetAllArtificial(string  artificialTypeName)
       {
           Type type = GetArtificialType(artificialTypeName);
 
           MethodInfo mInfo = typeof(Telerik.OpenAccess.ExtensionMethods).GetMethod("Extent").MakeGenericMethod(new Type[] { type });
           System.Collections.IEnumerable query = (System.Collections.IEnumerable)mInfo.Invoke(scope, new object[] { scope });
 
           return query.AsQueryable(); 
       }
Actually I was asking about way to get all objects from particular type knowing only his class name (user selectable at runtime).
The above code does the trick at the price of some use of reflection and really  dumb way of  obtaining  artificial class type  from dynamic assembly.

I was hoping that telerik api allow some way of achieving this since same functionality is present for example in OpenAccessDataSource component 

Best regards
Krasimir Filipov
0
Damyan Bogoev
Telerik team
answered on 20 Oct 2010, 06:32 PM
Hello Krasimir,

Currently we are working on this feature – Linq for artificial types. We will do our best to implement it for the next Q3 release which is scheduled for the middle of November.
You could also use OQL queries to retrieve this data instead of using reflection at the moment but I recommend you to wait for this functionality in Linq for the upcoming release, if it is possible for you.

Kind regards,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Krasimir
Top achievements
Rank 1
answered on 21 Oct 2010, 01:30 PM
I'm pretty open to avoid reflection and use the ODL query (see the initial post ) but was unable to find a way to obtain IQueriable from ODL query.  Could you  provide me with hint how this can be achieved? 

Best regards
Krasimir Filipov

0
Accepted
Damyan Bogoev
Telerik team
answered on 22 Oct 2010, 06:32 PM
Hi Krasimir,

Unfortunately, there is no way to cast the result from an OQL query to IQueryable.
I am sorry for the inconvenience caused.

Kind regards,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Denis Parchenko
Top achievements
Rank 1
answered on 31 May 2012, 09:32 AM
Hi Damyan,

Is there such possibility now?

Regards,
Denis

0
Damyan Bogoev
Telerik team
answered on 31 May 2012, 03:42 PM

Hello Denis,

You could use the IObjectScope.ExtentByName(string typeName) method as an entry point for constructing dynamic Linq queries with Telerik OpenAccess. This approach is applicable for artificial types as well.

Hope that helps. If any other questions arise, do not hesitate to contact us back.

Greetings,
Damyan Bogoev
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
General Discussions
Asked by
Krasimir
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Krasimir
Top achievements
Rank 1
Denis Parchenko
Top achievements
Rank 1
Share this question
or