How Linq uses data tables
This article mainly shows you "Linq how to use data tables", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Linq how to use data tables" this article.
First of all, let you learn about the data tables used by Linq, and then give a comprehensive introduction to the generated SQL statements.
Using datasheets, Linq can automatically create entity classes based on views by dragging views from Server Explorer / Database Explorer to the Ogamard R designer. We can manipulate the view in the same way as we do with data tables. Note here: the Omax R designer is a simple object-relational mapper because it only supports 1:1 mapping relationships. In other words, there can only be 1:1 mapping between an entity class and a database table or view. Complex mapping is not supported (for example, mapping an entity class to multiple tables). However, you can map an entity class to a view that joins multiple related tables. Let's write two examples using the Invoices and Quarterly Orders views included in the NORTHWND database as examples.
We use the following code to query ShipCity's invoice in London.
Var Q = from i in db.Invoices where i.ShipCity = = "London" select new {i.OrderID, i.ProductName, i.Quantity, i.CustomerName}
Here, the generated SQL statement is similar to the Linq usage data table:
SELECT [t0]. [OrderID]. [ProductName], [t0]. [Quantity], [t0]. [CustomerName] FROM [dbo]. [Invoices] AS [t0] WHERE [t0]. [ShipCity] = @ p0-- @ p0: Input NVarChar (Size = 6; Prec = 0; Scale = 0) [London]
The following example finds out the orders for each quarter.
Var Q = from qo in db.Quarterly_Orders select qo
Generate the SQL statement as follows:
SELECT [t0]. [CustomerID]. [CompanyName], [t0]. [City], [t0]. [Country] FROM [dbo]. [Quarterly Orders] AS [t0] above are all the contents of the article "how to use data sheets in Linq". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!