This question is locked. New answers and comments are not allowed.
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
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
0
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:
Hope that helps.
Greetings,
Damyan Bogoev
the Telerik team
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
![](/forums/images/avatarimages/default.gif)
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
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
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
![](/forums/images/avatarimages/default.gif)
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
Best regards
Krasimir Filipov
0
Accepted
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
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
![](/forums/images/avatarimages/7e7fd3ed-5a68-49f8-aa35-4a11b46ec56cavatar_1.png)
Denis Parchenko
Top achievements
Rank 1
answered on 31 May 2012, 09:32 AM
Hi Damyan,
Is there such possibility now?
Regards,
Denis
Is there such possibility now?
Regards,
Denis
0
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!