以下代码不起作用,因为它没有作为查询的正确类型出现。以下版本都不会起作用,我尝试将其作为ITable投射的底部版本不起作用,因为它表明我缺少参考。
我正在尝试让我的代码循环遍历第一个查询(工作)中找到的表,然后在该查询中找到这些列,以便我以后可以更新它们。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.Data;
namespace funwithsql
{
class Program
{
static void Main(string[] args)
{
UTILEntities context = new UTILEntities();
var tables = from data in context.custtables
select new
{
col1 = data.TableName.ToString(),
col2 = data.columnname.ToString()
};
var tableslist = tables.Select(s => new { col1 = s.col1, col2 = s.col2 }).ToList();
foreach (var table in tableslist)
{
var intable = context.GetType().GetProperty(table.col1.ToString()).GetValue(context,null);
var tline = from tdata in context.GetType().GetProperty(table.col1.ToString()).GetValue(context, null)
select tdata;
}
}
}
}