rnirnber
rnirnber

Reputation: 615

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

Assuming EF6.1 is in use....

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.....

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?

Upvotes: 0

Views: 56

Answers (1)

mnsr
mnsr

Reputation: 12437

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

To see SQL:

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

Upvotes: 1

Related Questions