This article is a mirror article of machine translation, please click here to jump to the original article.

View: 41452|Reply: 1

[Source] EF Core Series (5) executes SQL statements or views, stored procedures

[Copy link]
Posted on 2/19/2021 2:00:14 PM | | | |
EF Core Series 2 encapsulates OnModelCreating, creates indexes using reflections, and more
https://www.itsvse.com/thread-9392-1-1.html

EF Core Series (3) Entity Frame Shadow Attributes [Reprint]
https://www.itsvse.com/thread-9558-1-1.html

EF Core Series 4 looks at the generated SQL statements
https://www.itsvse.com/thread-9564-1-1.html
With Entity Framework Core, you can drop to the original SQL query when using a relational database. When the required query cannot be represented in LINQ, the raw SQL query can be used. You can also use raw SQL queries if using LINQ queries is causing inefficient SQL queries. The raw SQL query can return a generic entity type or a keyless entity type in the model.

Recap: Executing SQL statements and stored procedures with Entity Framework (EF).

Entity Framework (EF) executes SQL statements and stored procedures
https://www.itsvse.com/thread-9517-1-1.html
Perform SQL statement queries, updates, and deletes, and invoke stored procedures and views using the following methods:

  • FromSqlRaw
  • FromSqlInterpolated
  • ExecuteSqlRaw
  • ExecuteSqlInterpolated



FromSqlRaw and FromSqlInterpolated are mainly used for query operations
ExecuteSqlRaw and ExecuteSqlInterpolated perform add, update, and delete operations on the database, and return the number of affected rows


The end is an interpolated keyword, which is usually a parameter addition, deletion, modification and check, and a way to resist SQL injection attacks using string interpolation syntax. For example:

Output a SQL statement, the query conditions are not passed through splicing, as shown in the figure below:

C# Parameterized Parameters uses sp_executesql to execute sql statements
https://www.itsvse.com/thread-3111-1-1.html




There are a few limitations to be aware of when using native SQL queries:

SQL queries must return data for all attributes of the entity type.
The column names in the result set must match the column names to which the attributes are mapped. Note that this behavior is different from EF6. The attribute/column mapping relationship of the original SQL query is ignored in EF6, and the result set column names must match the attribute names.
SQL queries cannot contain associated data. However, in many cases, you can use the Include method immediately after the query to return correlated data (see Include Associative Data).


(End)




Previous:EF Core Series 4 looks at the generated SQL statements
Next:Fiddler replaces links, requests forwarding redirects
 Landlord| Posted on 6/14/2023 9:15:53 PM |
EF 6 executes native SQL statements, parameter injection problems
https://www.itsvse.com/thread-10610-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com