Obtain IQueryable for select all from artificial type

8 posts, 1 answers
  1. Krasimir
    Krasimir avatar
    14 posts
    Member since:
    Feb 2009

    Posted 11 Oct 2010 Link to this post

    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
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 14 Oct 2010 Link to this post

    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
  3. DevCraft banner
  4. Krasimir
    Krasimir avatar
    14 posts
    Member since:
    Feb 2009

    Posted 18 Oct 2010 Link to this post

    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
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 20 Oct 2010 Link to this post

    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
  6. Krasimir
    Krasimir avatar
    14 posts
    Member since:
    Feb 2009

    Posted 21 Oct 2010 Link to this post

    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

  7. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 22 Oct 2010 Link to this post

    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
  8. Denis Parchenko
    Denis Parchenko avatar
    2 posts
    Member since:
    Sep 2009

    Posted 31 May 2012 Link to this post

    Hi Damyan,

    Is there such possibility now?

    Regards,
    Denis

  9. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 31 May 2012 Link to this post

    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!
Back to Top
DevCraft banner