Entity, entity set and its application

Source: Internet
Author: User
I. EntityEntity writing in C #

In C #

Statement (1 ):

Public class UserInfo {public int UserID {get; set ;}}

Statement (2 ):

Public class UserinfoEntity {private string userid; 'define field name public string ID' define attribute item {get {return userid;} 'value [Get ...... End Get, which can be saved] set {userid = value;} 'value assignment [Set ...... End Set, which is saved]}

Summary: simple comparison. Method (1) is equivalent to method (2). It is obvious that method (1) is simpler.

(2) written in VB. NET as follows:

Written in VB. NET:
Public Class UserEntityPrivate _ userID As String 'defines the field name Public Property UserID () As String' defines the attribute item get'; value: [Get ...... End Get, which can be saved] Return _ userID End Get Set (value As String) 'value assignment [Set ...... End Set, which is saved] _ userID = value End SetEnd PropertyEnd Class

Note: an entity named UserEntity is listed above, which includes a userID attribute item named _ UserID. In practical use, there are generally multiple items. You only need to define the field name and corresponding attribute items (based on the value and value assignment needs.

Encapsulate an object attribute set into an object. An object attribute value is transmitted through the process of value assignment and value.

For example, a student (an object) has a student ID: studentID (20145113145), name (Wang Wu), gender sex, (male) class (rocket class), and ID card number ID (110120199008122014) and other attributes,

(3) usage:

Application

C # and VB. NET have the same usage. When the Value is set to UserEntity. UserID, UserEntity. UserID = Value (Value is set ).

II. Entity Set

Entity Set

An object set is a set of entities with the same attribute items.

The relationship between entities and entity sets is like the relationship between a student and a class.

In a data table, a row carries a set of information (attribute set) of an object, that is, an object. Multiple rows are the attribute set of a group of objects.

You only need to pass the individual information (one row in the table), which can be satisfied with the entity. However, if you want to pass the information of a group (multiple rows in a table ), the entity set is considered.

(1) tables and generics are used to represent an object set. To convert a table to an object set (vb.net), follow these steps:

Indicates:

DataTable data type conversion to generic (entity set)

Imports System. collections. generic 'reference Generic set Imports System. reflection 'references Reflection and uses its propertyinfo' to assemble an object into an object set 'to convert the 'able able type' to a generic 'entity set' ('entity set ') public Class genericCollectionPublic Shared Function converToList (Of T As {New}) (ByVal sqlDatatable As DataTable) As List (Of T) Dim myList As New List (Of T) 'instantiate a generic set Dim myType As type' to define a Type name_variable myType = GetType (T) 'placement type Dim sqlDatarow As datarow' queries the table's row set Dim tmpName As String = String. empty 'defines a temporary variable 'to traverse all data rows of the DataTable For Each sqlDatarow In sqlDatatable. rows Dim myT As New T 'instantiation type' defines an attribute set Dim propertys () As PropertyInfo propertys = myT. getType (). getProperties () 'defines an attribute Dim pr As propertyinfo' to traverse all attributes For Each pr In propertys tmpName = pr. the name' assigns the attribute Name to the variable container 'and checks whether the DataTable contains this column (column Name = attribute Name) If (sqlDatatable. columns. contains (tmpName) then' determines whether to edit If (pr. canWrite = False) Then Continue For End If 'get the Object Dim value As Object = sqlDatarow (tmpName) 'based on the attribute name' to determine whether the Object body is empty If (value. toString <> DBNull. value. toString) Then pr. setValue (myT, value, Nothing) 'uses reflection to set the attribute End If Next myList. add (myT) 'add type set Next Return mylist' Return generic set End Function End Class

(2) entity set can be used in this way

Yes

Data Query, verification, and usage in programs are common and database access is inevitable. However, data access is time-consuming, especially in the face of big data. When multiple users perform operations and share data, reducing data access is a matter of efficiency.

Object set myList as Liss (of T_Entity)

Dim k as Integer = 1' is defined and initialized As 1Dim resumecash as Double'. The variable myList = select_bll.select (T_Entity) If myList. count> 0 then' prevent empty Do While k <myList. count Or k = myList. count Dim new_entity As Entity. mainEntity = myList. item (k-1) If new_entity.Style = "fixed user" then' sets conditions, specifies the "Fixed user" field, and selects records that meet the conditions. CardNum = cardNum + 1' accumulate the number of qualified records fastenCash = fastenCash + carditem. cash 'fixed user sales Gold End If resumecash = resumecash + new_en.Consumecash 'cumulative consumption amount k = k + 1 LoopEnd If

Note: The information obtained by the above code is equivalent to the number of rows (number of entities) mapped to a table) specifies a specific record for execution, the number of qualified fields, and the content of any field.

This form of information mining can reduce the load on multiple databases, reduce the number of visits when multiple users perform operations, reduce threads and congestion caused by queuing.

 

Entity, entity set and its application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.