Table name as a parameter

4 posts, 0 answers
  1. bin
    bin avatar
    11 posts
    Member since:
    Jun 2010

    Posted 13 Apr 2011 Link to this post

    Hi sir,

    i am using the ObjectScope of  telerik open access.

    How can i select data by sending the table name as parameter using linq query ?

    thanks

  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 15 Apr 2011 Link to this post

    Hi bin,

     Unfortunately at the moment it is impossible to retrieve information based on the table name. However it should be possible to retrieve the persistent type name based on the table name using the metadata model that is available trough the scope. 

    You can do so using code like: 

    var model = scope.Database.MetaData;
    string tableName = "table-name";
     
    var persistentType = model.PersistentTypes
        .FirstOrDefault(x => x.Table != null && string.Equals(x.Table.Name, tableName));
    string typeName = persistentType.FullName;

    However this might only help you if you are using OQL to retrieve data. 

    I hope this is helpful. 

    All the best,
    Serge
    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. XXXX
    XXXX avatar
    57 posts
    Member since:
    Jun 2008

    Posted 13 May 2011 Link to this post

    This is of interest to me as I want to query a table that is not part of the DomainModel.

    Using IObjectScope.GetSqlQuery will be database depentant and I would like to solve this without having diffrent queries depending what the backend type is.

    Has anyone a workaround ?
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 17 May 2011 Link to this post

    Hello Bjössi,

    I am afraid that the only way to retrieve information from a table which is not part of the model is to create a stored procedure in the database which returns the needed data. Then you can add this stored procedure to your model and execute it as a method of the OpenAccessContext instance. This method would return an object array which you can easily traverse to get the data.

    Regards,
    Alexander
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Back to Top