Obtain data from db.Query<T> as IQuerable<object>

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
dqrest
Posts: 32
Joined: Tue 15 Sep 2015 06:01

Obtain data from db.Query<T> as IQuerable<object>

Post by dqrest » Tue 27 Oct 2020 13:14

Hello!

I have queries wich are generated for many pages with different classes by the custom builder. That's why I want to execute a query directly with any type. How can I do it in dotConnect for Oracle 9.13.1098.0?

For example, for query "select name, id from test"
I have to create the class

Code: Select all

public class TestName 
{
   public string name {get; set;}
   public int id {get;set;}
}

and execute the code

Code: Select all

var query = db.Query<TestName>("select name, id from test")
But I have many queries and classes and there is no opportunity to create all classes in C#.
How can I execute this query and obtain the result as IQuerable<object>?
Note that after using

Code: Select all

var query = db.Query<object>("select name, id from test")
I have IQuerable<object> but in the item there is no any data.

dqrest
Posts: 32
Joined: Tue 15 Sep 2015 06:01

Re: Obtain data from db.Query<T> as IQuerable<object>

Post by dqrest » Wed 28 Oct 2020 11:02

Find the following solution.

Code: Select all

 public static IQueryable Query(DataContext context, Type type, string sql)
 {
            var method = context?.GetType()?.GetMethods()?.FirstOrDefault(m => m.Name == "Query" && m.IsGenericMethod);
            if (method == null) return null;
           return method.MakeGenericMethod(type)?.Invoke(context, new[] {sql, (object) null }) as IQueryable;
 }

Post Reply