With the help of Entity Framework, you may never write a single SQL Query code in your programming projects. Some of the benefits of Entity framework include:
- Visual Studio intellisense
- Compile checking
- Faster development
- Auto generated domain objects
- Lazy loading, etc.
The easiest way to view the generated SQL is to use a profiler tool that's included in database management tools (for instance, SQL Server Manangement Studio). Using this tool, you can monitor all SQL statements executed against the database. But using this tool requires that you have access to the database. Fortunately, with Entity Framework 4, you can use ObjectSet
Here's the example code on how to do it in C# and VB.NET:
C#:
var result = ctx.Orders.Where(o => o.Date.Year == DateTime.Now.Year); var SQL = (result as ObjectQuery).ToTraceString();
Dim result = ctx.Orders.Where(Function(o) o.Date.Year = DateTime.Now.Year) Dim SQL = TryCast(result, ObjectQuery).ToTraceString()
0 comments:
Post a Comment