简体   繁体   English

实体框架通过IQueryable返回SQL的任何方式<T>

[英]Entity Framework any way to return SQL as a result of IQueryable<T>

Assuming EF6.1 is in use.... 假设正在使用EF6.1。...

Assuming that 'Category' is a POCO type that EF persists, that 'context' has a DbSet property called 'categories', that 'x' is defined as a legitimate local of type int, and that c.ID is also of type int..... 假设“类别”是EF持续存在的POCO类型,则“上下文”具有一个名为“ categories”的DbSet属性,该“ x”被定义为int类型的合法本地,而c.ID也是int类型.....

Given the following expression 给出以下表达式

context.Categories.Where<Category>((Category c) => {return c.ID == x});

Is there a way, before the query happens, to return the compiled SQL statement as a string without hitting the Database? 在查询发生之前,是否有一种方法可以将已编译的SQL语句作为字符串返回而不触及数据库?

public IQueryable<Category> GetCategory(int x)
{
   return context.Categories.Where<Category>(c => c.ID == x);
}

To see SQL: 要查看SQL:

Console.WriteLine(GetCategory(1).ToString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM