Accessing SQL from Entity Framework Core Queries in ASP.NET Core
In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/
The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.
I am using using .net core 2.1 as well.
Is there another or similar approach available?
Thanks.
c# entity-framework asp.net-core
|
show 3 more comments
In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/
The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.
I am using using .net core 2.1 as well.
Is there another or similar approach available?
Thanks.
c# entity-framework asp.net-core
In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757
– Gabriel Luci
Nov 24 '18 at 20:58
@GabrielLuci Yes, agreed. The reference you provided has the issue.
– JamieMeyer
Nov 24 '18 at 21:02
So did you try that one? People in the comments claim that it works with 2.1
– Gabriel Luci
Nov 24 '18 at 21:42
The original post, as well as my previous response to you indicate this is the case. Do you have a different result?
– JamieMeyer
Nov 24 '18 at 21:47
Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.
– Gabriel Luci
Nov 24 '18 at 22:26
|
show 3 more comments
In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/
The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.
I am using using .net core 2.1 as well.
Is there another or similar approach available?
Thanks.
c# entity-framework asp.net-core
In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/
The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.
I am using using .net core 2.1 as well.
Is there another or similar approach available?
Thanks.
c# entity-framework asp.net-core
c# entity-framework asp.net-core
edited Nov 24 '18 at 22:27
Gabriel Luci
11.2k11525
11.2k11525
asked Nov 24 '18 at 20:54
JamieMeyerJamieMeyer
346214
346214
In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757
– Gabriel Luci
Nov 24 '18 at 20:58
@GabrielLuci Yes, agreed. The reference you provided has the issue.
– JamieMeyer
Nov 24 '18 at 21:02
So did you try that one? People in the comments claim that it works with 2.1
– Gabriel Luci
Nov 24 '18 at 21:42
The original post, as well as my previous response to you indicate this is the case. Do you have a different result?
– JamieMeyer
Nov 24 '18 at 21:47
Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.
– Gabriel Luci
Nov 24 '18 at 22:26
|
show 3 more comments
In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757
– Gabriel Luci
Nov 24 '18 at 20:58
@GabrielLuci Yes, agreed. The reference you provided has the issue.
– JamieMeyer
Nov 24 '18 at 21:02
So did you try that one? People in the comments claim that it works with 2.1
– Gabriel Luci
Nov 24 '18 at 21:42
The original post, as well as my previous response to you indicate this is the case. Do you have a different result?
– JamieMeyer
Nov 24 '18 at 21:47
Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.
– Gabriel Luci
Nov 24 '18 at 22:26
In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757
– Gabriel Luci
Nov 24 '18 at 20:58
In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757
– Gabriel Luci
Nov 24 '18 at 20:58
@GabrielLuci Yes, agreed. The reference you provided has the issue.
– JamieMeyer
Nov 24 '18 at 21:02
@GabrielLuci Yes, agreed. The reference you provided has the issue.
– JamieMeyer
Nov 24 '18 at 21:02
So did you try that one? People in the comments claim that it works with 2.1
– Gabriel Luci
Nov 24 '18 at 21:42
So did you try that one? People in the comments claim that it works with 2.1
– Gabriel Luci
Nov 24 '18 at 21:42
The original post, as well as my previous response to you indicate this is the case. Do you have a different result?
– JamieMeyer
Nov 24 '18 at 21:47
The original post, as well as my previous response to you indicate this is the case. Do you have a different result?
– JamieMeyer
Nov 24 '18 at 21:47
Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.
– Gabriel Luci
Nov 24 '18 at 22:26
Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.
– Gabriel Luci
Nov 24 '18 at 22:26
|
show 3 more comments
2 Answers
2
active
oldest
votes
Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.
Here is what I did:
- Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.
- Added
Microsoft.EntityFrameworkCore
version 2.1.4 from NuGet. - Created an
IQueryableExtensions
class and pasted the code.
It compiles.
The RelationalQueryModelVisitor
class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.
add a comment |
Would using their logging functionality be sufficient?
https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging
public static readonly LoggerFactory MyLoggerFactory
= new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
.UseSqlServer(...);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462278%2faccessing-sql-from-entity-framework-core-queries-in-asp-net-core%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.
Here is what I did:
- Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.
- Added
Microsoft.EntityFrameworkCore
version 2.1.4 from NuGet. - Created an
IQueryableExtensions
class and pasted the code.
It compiles.
The RelationalQueryModelVisitor
class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.
add a comment |
Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.
Here is what I did:
- Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.
- Added
Microsoft.EntityFrameworkCore
version 2.1.4 from NuGet. - Created an
IQueryableExtensions
class and pasted the code.
It compiles.
The RelationalQueryModelVisitor
class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.
add a comment |
Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.
Here is what I did:
- Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.
- Added
Microsoft.EntityFrameworkCore
version 2.1.4 from NuGet. - Created an
IQueryableExtensions
class and pasted the code.
It compiles.
The RelationalQueryModelVisitor
class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.
Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.
Here is what I did:
- Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.
- Added
Microsoft.EntityFrameworkCore
version 2.1.4 from NuGet. - Created an
IQueryableExtensions
class and pasted the code.
It compiles.
The RelationalQueryModelVisitor
class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.
edited Nov 25 '18 at 1:55
answered Nov 25 '18 at 0:01
Gabriel LuciGabriel Luci
11.2k11525
11.2k11525
add a comment |
add a comment |
Would using their logging functionality be sufficient?
https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging
public static readonly LoggerFactory MyLoggerFactory
= new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
.UseSqlServer(...);
add a comment |
Would using their logging functionality be sufficient?
https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging
public static readonly LoggerFactory MyLoggerFactory
= new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
.UseSqlServer(...);
add a comment |
Would using their logging functionality be sufficient?
https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging
public static readonly LoggerFactory MyLoggerFactory
= new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
.UseSqlServer(...);
Would using their logging functionality be sufficient?
https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging
public static readonly LoggerFactory MyLoggerFactory
= new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
.UseSqlServer(...);
answered Nov 24 '18 at 23:13
MohoMoho
11.1k11723
11.1k11723
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462278%2faccessing-sql-from-entity-framework-core-queries-in-asp-net-core%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757
– Gabriel Luci
Nov 24 '18 at 20:58
@GabrielLuci Yes, agreed. The reference you provided has the issue.
– JamieMeyer
Nov 24 '18 at 21:02
So did you try that one? People in the comments claim that it works with 2.1
– Gabriel Luci
Nov 24 '18 at 21:42
The original post, as well as my previous response to you indicate this is the case. Do you have a different result?
– JamieMeyer
Nov 24 '18 at 21:47
Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.
– Gabriel Luci
Nov 24 '18 at 22:26