EF执行SQL返回动态类型
using System;
using System.Data.Common;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
using (var entity = new ldhEntities())
{
var context = ((IObjectContextAdapter)entity).ObjectContext;
string myQuery = @"select affairinfo.ID, affairinfo.NAME from affairinfo";
var data = (new ObjectQuery<DbDataRecord>(myQuery, context)).ToList();
foreach (DbDataRecord rec in data)
{
Console.WriteLine("ID {0}; NAME {1}", rec[0], rec[1]);
//Console.WriteLine("ID {0}; NAME {1}", rec["ID"], rec["NAME"]);
}
}
Console.Read();
}
}
}