我正在使用 Entity Framework4(代码优先)。
我想查看生成的查询。
我在 Stackoverflow 中找到了这段代码。
var trace = ((System.Data.Objects.ObjectQuery)result).ToTraceString();
但这不起作用,错误消息说,
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[PJ.Mysql.Entities.Order]' to type 'System.Data.Objects.ObjectQuery'.
我的代码是,
[HttpGet]
public void test()
{
EFOrdersRepository ordersRepository = new EFOrdersRepository();
var query = ordersRepository.Orders;
var result = from x in query
where x.orderid == 99008326
select x;
var trace = ((System.Data.Objects.ObjectQuery)result).ToTraceString(); //it does not work
Response.Write(trace);
}
EFOrdersRepository.cs
public class EFOrdersRepository
{
private EFMysqlContext context = new EFMysqlContext();
public IQueryable<Order> Orders
{
get { return context.orders; }
}
}
EFMysqlContext.cs
class EFMysqlContext : DbContext
{
public DbSet<Order> orders { get; set; }
}
我真的很想解决这个问题=3,有人知道吗?