-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explain how keyless types can be used to execute raw SQL query for "non-entities" #969
Comments
It this |
@ajcvickers @Paul-Dempsey it's seems improper way. I'm getting "Cannot create a DbSet for 'KnowlageNodeRecurcive' because this type is not included in the model for the context." If data type not registered in context, as table. Perhaps there are no way to use this, and we should be stuck with raw ADO SqlCommand. :-( |
@ajcvickers thank you so much!!! It helped. I've added For other who would be interested and would be reading this thread. P.S. should this issue be opened? It's related to updating documentation. |
I'm getting an Exception:
But I have no idea of what that means. 😕 |
I totally agree, to get my raw query working I had to make configurations on |
Here's how you can achieve this:
|
Duplicate of #410 |
Tried to use weitzhandler code in ASP.NET MVC Core 5 with npgsql. Line throws error ArgumentNullException: Value cannot be null. (Parameter 'value') How to fix this code so that parameters with null values are also accepted ? |
@kobruleht , you can't pass nulls to SqlParameters. Use DbNull.Instance or something like that. But this should not be case with EF queries. But you are referring to ADO.net and SqlCommand which as ALLWAYS representing nulls with DbNull since classic .Net Framework 1.0 |
Should if statement added which passes DbNull in parameter is null ? I posted it also in https://stackoverflow.com/questions/65754699/get-value-from-sql-select-if-parameter-may-be-null |
You could use ?? Operator to replace values with DbNull But better to use EF method, it would convert nulls, and would be able to map back to classes |
I need to run arbitrary sql queries which can return string, decimal?, bool? and other scalar values. There is no EF class for result. How to use EF method for this ? Like
I found some code which injects keyless type dynamically to DbContext in OnModelCreated method. Maybe this can used if EF method is better. |
I changed
to
|
this does not support something like List as a return type? |
I dont need List resturn type. Parameters passed to this method are object types. Tried your code as:
|
In EF6 there were method to call raw sql for non entity https://docs.microsoft.com/en-us/ef/ef6/querying/raw-sql#writing-sql-queries-for-non-entity-types
It's seems impossible in EF Core, and RelationalDatabaseFacadeExtensions.ExecuteSqlCommand (eg context.Database.ExecuteSqlCommand ) don't allow selects, only non-query statements.
Should I create new DbSet for non entity dynamically? or other workarounds?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: