In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use ADO.NET object query". In daily operation, I believe many people have doubts about how to use ADO.NET object query. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use ADO.NET object query". Next, please follow the editor to study!
The ObjectQuery generic class represents a query that returns a collection of zero or more typed entity objects. Object queries always belong to the existing object context. This context provides the connection and metadata information needed to write and execute queries.
A typed ObjectContext contains a set of properties that return a typed ObjectQuery instance. Each entity type in the model has one of these attributes. These properties make it easier to create instances of typed ObjectQuery. An object query is executed in the following scenario: when an operation is performed on it, for example, during the foreach (C #) or For Each (Visual Basic) enumeration. When allocated to populate the List collection. When the Execute method is explicitly called. When a LINQ query execution operator, such as First or Any, is called.
The following query returns a Contact object whose first and last name is specified by the passed parameter:
'Get the contacts with the specified name. Dim contactQuery As ObjectQuery (Of Contact) = _ context.Contact _ .Where ("it.LastName = @ ln AND it.FirstName = @ fn", _ New ObjectParameter ("ln", lastName), _ New ObjectParameter ("fn", firstName))
For a complete example of how to write and execute a query using an object context, see how to: execute a query that returns an entity type (entity framework). For more information about Entity SQL queries, see the Entity SQL language.
Query projection
When ADO.NET object queries are used to return entity data model (EDM) data as entity objects, ADO.NET object queries also support projection, so it is difficult to materialize the data returned by projection into entity types. ObjectQuery uses the DbDataRecord type for projections that return non-entity types, which can be nested results or anonymous types. Simple types, such as Int32 or String, are used with projections that return a single property value.
The following considerations apply to query projection: ObjectQuery can be initialized to represent a single scalar result rather than a scalar result collection. Some extension methods require the result of the collection as input. In this case, an ArgumentException is thrown when one of the methods is called, as shown in the following example.
'Define a query projection that returns'a single scalar value rather than a collection. Dim scalarQuery As ObjectQuery (Of Int32) = _ New ObjectQuery (Of Int32) ("100s", advWorksContext) 'Calling an extension method that requires a collection' will result in an exception. Dim hasValues As Boolean = scalarQuery.Any () at this point, the study on "how to use ADO.NET object query" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.