Search code examples
c#asp.netlinqlinqpad

LinqPad can not return correct table type


I use LinqPad connect to sql server. There is a standard database Northwind with table Product. I need get the table property information dynamic(read table name from client console input). Unfortunately, LinqPad hide the table real type. What ever how I try, it always return null to me.

please be aware, this question is not same with others. I need get table properties relate to user input table name like "Products". The challenge part is I do not need get string "LINQPad.User.Products" properties, but I do need get the table LINQPad.User.Products properties. The answer for question Get properties and values from unknown object can not solve my question. Actually my question is same with that answer, just code format is different.

var propertyInfo = (Type.GetType(fullTableName)).GetProperties();

var tableName = Console.ReadLine();
string fullTableName =  "LINQPad.User." + tableName;
var propertyInfo = (Type.GetType(fullTableName)).GetProperties();


Solution

  • To get the properties, you can use something along the lines of this...

    void Main()
    {
        string tableName = Console.ReadLine();
    
        Type.GetType("UserQuery").GetProperty(tableName)
                                 .PropertyType
                                 .GenericTypeArguments
                                 .First()
                                 .GetProperties()
                                 .Dump("The properties of the " + tableName + " table");
    
    }