One of the three core contents of programming: Data processing

Source: Internet
Author: User

The ADO. NET Entity Framework is an object-relational mapping schema that gives mapping information between a database and an entity class using the CSDL conceptual schema definition language and the SSDL storage schema definition language. This architecture is the most easy-to-use high-level data processing scheme at this stage.

The Visual Studio integrated development environment comes with an Entity Data Model Designer that uses an. edmx file to save information and generates a CSDL conceptual schema definition language . csdl file,SSDL storage schema definition language the. ssdl file and the MSL Mapping specification language . msl file.

I. Conceptual layer CSDL 1. Miscellaneous

Entity container: System.Data.Objects.ObjectContext, System.Data.Entity.DbContext

Entity Data Model tools: Visual Studio built-in mapping and modeling tools (Code first uses data annotations and the fluent API)

Entity SQL command: EntityCommand

Management Services: System.transaactions, entitytransaction

Primitive type : Primitivetype–>iextendeddatarecord obj. GetValue (Index)

There are structural types :structuraltype–>

Iextendedddatarecord record;

int count= record. DatarecordInfo.FieldMetadata.Count;

int index=0;

Record. GetName (index);

if (record. IsDBNull (Index) = = False) {

Builtintypekind fieldtypekindd = record. Datarecordinfo.fiedmetadata[index]. FieldType.TypeUsage.EdmType.BuiltInTypeKind;

if (Fieldtypekind = = Builtintypekind.primitivetype) record. GetValue (index);}

Address Type :reftype–>

if (record. IsDBNull (Index) ==false) {

if (Fieldtypekind = = Builtintypekind.reftype) {

EntityKey key = record. GetValue (index) as EntityKey;

Key. entitySetName;

foreach (Entitykeymember keymember in key. Entitykeyvalues) {

Keymember.key;

Keymember.value;}}}

Complex Type :dbdatarecord–>

DbDataRecord R;

for (int i =0; i < r.fieldcount; i++) R.getvalue (i);

Nested sets :->

EntityDataReader RDR;

Rdr. Read ();

DbDataReader reader = RER. Getdatareader (index);

Reader. Read ();

reader["ID"];

reader["Date"];

2. Entity Data Model:

Entity type, association type, property

namespace : <schema namespce= ""/>

<using namespace= "" aliass= ""/>

Primitive Type :

Binary

Boolean

Byte

DateTime Date and Time

DateTimeOffset minute offset relative to GMT

Decimal

Double

Float

Guid 16 byte Unique identifier

Int16

Int32

Int64

SByte

String

Time of day

inheritance : The root type must have entity keys; Multiple inheritance is not supported; Inheritance for implementation inheritance cannot overwrite base classes.

Association : 1. Name; 2. Two association end; 3. Associated operation.

<association name= "" >

<end type= "entity type" role= "Association End Name" multiplicity= "*"/>

<end type= "entity type" multiplicity= "1" >

<ondelete action= "Cascade"/>

</End>

</Association>

Correlation Set : 1. Association set name; 2. To include an association of its instances; 3. Two association sets; 4. The same association can have multiple correlation sets, but the correlation set cannot share the wide-set.

<entitycontainer nmae= "Bookscontainer" >//Container

<entityset name= "Books" entitytype= "Booksmodel.book"/>//entity set

<entityset name= "Publishers" entitytype= "Booksmodel.author"/>//entity set

<associationset name= "Publishedby" association= "Booksmodel.publishedby" >//Correlation Sets and associations

<end role= "book" entityset= "Books"/>//Association set end

<end role= "Publisher" entityset= "publishers"/>//Association set end

</AssociationSet>

</EntityContainer>

Complex Type : 1. Name; 2. Attribute; 3. Cannot exist independently, cannot participate in association

<complextype name= "Adderess" >

<property type= "String" name= "StreetAddress" nullable= "false"/>

<property type= "String" name= "City" nullable= "false"/>

</ComplexType>

entity type : 1. Must have an entity key; 2. Properties; 3. Navigation (association) properties; 4. The same type and key value are equal

<entitytype nmae= "Publisher" >

<Key>

<propertyref nmae= "Id"/>

</Key>

<property type= "Int32" name= "Id" nullable= "false"/>

<property type= "booksmodel.address" name= "Address" nullable= "false"/>

<navigationproperty name= "Books" relationship= "Booksmodel.publishedby" fromrole= "Publisher" torole= "book"/>

</EntityType>

entity containers : 1. Entity sets, association sets, logical groupings of function imports.

<entitycontainer name= "Bookscontainer" >

<entityset name= "Books" entitytype= "Booksmodel.book"/>

<entityset name= "Publishers" entitytype= "Booksmodel.publisher"/>

<associationset name= "Publishedby" association= "Booksmodel.publishedby" >

<end role= "book" entityset= "Books"/>>

<end role= "Publisher" entityset= "publishers"/>

</AssociationSet>

</EntityContainer>

entity keys : 1. Consists of a set of non-null and immutable primitive type properties; 2. Entity keys must be defined in the root class

<Key>

<propertyref name= "Name"/>

</Key>

foreign keys : 1. When one of the two entities has a foreign key attribute, a referential integrity constraint is used to define the association between the two entity types.

Referential integrity constraints : 1. Entities referencing entity keys of another entity type are dependent, 2. The principal side is quoted; 3. The relying end is provided with a set of properties that reference the entity key of the principal side; 4. Define referential integrity constraints in the association.

<association name= "Publishedby" >

<end type= "Booksmodel.book" role= "book" multiplicity= "*"/>

<end type= "Booksmodel.publisher" role= "Pbulisher" multiplicity= "1"/>

<ReferentialConstraint>//constraints

<principal role= "Publisher" >//Principal side

<propertyref name= "Id"/>//Principal side entity key

</Principal>

<dependent role= "book" >//Dependent end

<propertyref name= "PublisherID"/>//dependency Property Reference Principal side entity key

</Dependent>

</ReferentialConstraint>

</Asscociation>

Navigation (Association) Properties : 1. Name; 2. Association; 3. Association End

<navigationproperty name= "name" relationship= "Association" fromrole= "proximal" torole= "far End"/>

entity set : 1. The entity key is unique in the set; 2. Instances do not exist in other entity sets; 3. Entity types in the conceptual model do not have to define an entity set.

Properties : 1. property name; 2. property type; 3. A set of aspects (rules).

<property type= "type" name= "name" nullable= "aspect"/>

aspects (rules) :

Collation ordered sequence applies to string

ConcurrencyMode Open concurrency Check

Default Defaults

FixedLength length is variable for binary, String

MaxLength Maximum length applies to binary, String

Whether the Nullable can be null

Precision digits for decimal, DateTime, DateTimeOffset, time

Scale decimal number applies to decimal

Whether Unicode is stored as Unicode applies to string

Model declaration Functions : Declared in a conceptual model, defined in a hosted or stored environment.

<functionimport name= "Updatepublisher" >

<parameter nmae= "Publilsherid" mode= "in" type= "Int32"/>

<parameter name= "Pblishername" mode= "in" type= "String"/>

</FunctionImport>

model definition Functions : Defined with Entity SQL.

<function name= "Getyearsinprint" returntype= "Edm.int32" >

<parameter name= "book" type= "Booksmodel.book"/>

<DefiningExpression>

Year (Currentdatetime ()) –year (book. Publisheddate as DateTime))

</DefiningExpression>

</Function>

3. Quick reference

1 Association (Association). Name (Close joint)

1.1 Documentation (Document information)

1.1.1 Summary (short description)

1.1.2 LongDescription (Detailed description)

1.2 End (end). Type (entity type). Role (name). Multiplicity (number of heavy)

1.2.1 OnDelete (defined as run-times non-data-source linkage deletion). Action (whether to delete Cascade | None)

1.3 ReferentialConstraint (Referential integrity constraints)

1.3.1 Principal (principal side). Role (end name)

1.3.1.1 PropertyRef (main side key). Name (key name)

1.3.2 Dependent (dependent side). Role (end name)

1.3.2.1 PropertyRef. Name

1.4 Annotation Elements

2 Associctionset (correlation set). Name (Association set name). Association (association type)

2.1 End. EntitySet (entity set). Role (end name)

3 function (functions). Name (name of the function). ReturnType (return type)

3.1 Parameter (parameter). Name (parameter name). Type (primitive type | entity type | complex Type | line type | reference type). Mode (In | Out | InOut). MaxLength (maximum length). Precision (Precision). Scale (number of decimal digits). Nullable (whether it is nullable). DefaultValue (default value). FixedLength (whether fixed length). Unicode (whether Unicode). Collation (sort sequence string)

3.2 Definingexpression (Entity SQL)

3.3 ReturnType (return type). ReturnType (return type)

3.3.1 CollectionType (collection type). Type (types) . Nullable. DefaultValue. MaxLength. FixedLength. Precision. Scale. Unicode. Collation. ElementType (type of Element)

3.3.1.1 CollectionType (collection type)

3.3.1.2 referencetype (reference type). Type (referenced entity type)

3.3.1.3 RowType (line type)

3.3.1.3.1 Property (attribute) . Name. Type. Nullable. DefaultValue. MaxLength. FixedLength. Precision. Scale. Unicode. Collation

3.3.1.4 TypeRef (type Reference). Type (referenced). Nullable. DefaultValue. MaxLength. FixedLength. Precision. Scale. Unicode. Collation

3.3.2 Referencetype

3.3.3 RowType

4 FunctionImport (Import function). Name. ReturnType. EntitySet (return type is the entity set)

4.1 Parameter

5 ComplexType (complex type). Name. BaseType (base class). Abstract (whether it is an abstraction type)

5.1 Property. ConcurrencyMode (whether for optimistic concurrency check) other similar property

6 aspects (rules) apply to property (attribute), TypeRef (type Reference), Parameter (parameter) CollectionType (collection type)

7 Primitive types

8 annotation Element (custom element)

9 Schema (Root). Namespace (namespace). Alias (aliases). xmlns (XML namespace). XMLNS:CG (XML subspace)

9.1 Using (import namespace). Namespace (the imported namespace). Alias (aliases)

9.2 EntityContainer (Entity container). Name. Extends (contains the contents of another entity container)

9.2.1 EntitySet (Entity set). Name (entity set name). EntityType (Entity type)

9.2.2 AssociationSet

9.2.3 FunctionImport

9.3 EntityType (entity type). Name. BaseType (base class). Abstract (abstraction Class). OpenType (whether it is an open entity type)

9.3.1 Key (Key)

9.3.1.1 PropertyRef (Property Reference). Name (the name of the property referenced)

9.3.2 Property

9.3.3 NavigationProperty (Navigation properties). Name. Relationship (association). Torole (terminal). Fromrole (Start)

9.4 assocaciation

9.5 ComplexType

9.6 Function

Second, storage layer SSDL

Data definition language: DDL

Connection string Parameters: Provider provider name, Provider Connection string connection string, Metadata metadata and mapped resource, name of the connection in application configuration.

Data provider: EntityClient

Manage Connections: entityconnection

Connection string: Entityconnectionstringbuilder

Results of reading command target tree: EntityDataReader (Iextendeddatarecord)

1. Quick reference

1 Schema Framework

1.1 Association Association

1.1.1 End End

1.1.1.1 OnDelete Associated Delete

1.1.2 ReferentialConstraint FOREIGN KEY constraint

1.1.2.1 Pricipal main body side

1.1.2.1.1 PropertyRef Property Reference

1.1.2.2 Dependent Dependent End

1.1.2.2.1 PropertyRef

1.2 EntityType entity class

1.2.1 Key

1.2.1.1 PropertyRef

1.2.2 Property Properties

1.3 EntityContainer entity Container

1.3.1 EntitySet Entity set

1.3.1.1 definingquery definition Query

1.3.2 AssociationSet Correlation Set

1.3.2.1 End End

1.4 Function functions

1.4.1 CommandText database SQL segment

1.4.2 Parameter Parameters

Three, the mapping layer MSL 1. Quick reference

1 Mapping The root of the mapping framework. Space "C-s"

1.1 Alias aliases. Key alias. Value namespace

The 1.2 entitycontainermapping conceptual model entity container is mapped to the storage Model entity container. CdmEntityContainer the conceptual Model entity container. Storagemodelcontainer Storage Model entity container. Generateupdateviews (true| False)

1.2.1 EntitySetMapping entity set mappings. The Name conceptual model entity set. TypeName The conceptual model entity type. StoreEntitySet storage Model entity set. Makecolummnsdistinct whether to return only non-peers

1.2.1.1 entitytypemapping entity mappings. TypeName Conceptual Model Entity

1.2.1.1.1 mappingfragment entities are mapped to tables or views. Storeentitysset a table or view. MAKECOLUMNSDISTINCT only return non-peers

1.2.1.1.1.1 complextypemapping Complex Type mappings. TypeName Complex Types

The 1.2.1.1.1.1.1 ScalarProperty property is mapped to a list or parameter. The Name conceptual model property. ColumnName table column. The name of the parametername parameter. Version (Current | Original)

1.2.1.1.1.2 ScalarProperty

1.2.1.1.1.3 Condition conditions. ColumnName table column. Name property names. Whether the IsNull is null. Value comparison values

1.2.1.1.2 modificationfunctionmapping Insert, UPDATE, and delete functions are mapped to stored procedures

1.2.1.1.2.1 deletefunction Delete function. FunctionName a function in the storage model. Rowsaffectedparameter the name of the output parameter of the affected function

1.2.1.1.2.1.1 AssociationEnd associated Property mappings. The AssociationSet association name. The From association of the Fromrole. To associated Torole

1.2.1.1.2.1.2 Complexproperty Complex attribute mappings. Name of the complex property of the name conceptual model entity type. TypeName Property Type

1.2.1.1.2.1.3 Scarlarproperty

1.2.1.1.2.2 insertfunction Insert Function

1.2.1.1.2.2.1 AssociationEnd

1.2.1.1.2.2.2 Complexproperty

1.2.1.1.2.2.3 resultbinding return value mappings. Name of the Entity property. ColumnName table Column

1.2.1.1.2.2.3 Scarlarproperty

1.2.1.1.2.3 updatefunction

1.2.1.1.2.3.1 AssociationEnd

1.2.1.1.2.3.2 Complexproperty

1.2.1.1.2.3.3 resultbinding

1.2.1.1.2. 3.3 Scarlarproperty

1.2.1.1.3 ScalarProperty

1.2.1.1.4 Condition

1.2.1.2 QueryView Read-only result view SQL query. TypeName Conceptual Model type name

1.2.1.3 MappingFragment

1.2.2 AssociationSetMapping Association set mappings. Name Association set name. TypeName the correlation set type. StoreEntitySet table

1.2.2.1 QueryView

1.2.2.2 EndProperty Association-side mapping. Name End Name

1.2.2.2.1 ScalarProperty

1.2.2.3 Condition

1.2.2.4 ModificationFunctionMapping

1.2.2.4.1 InsertFunction and DeleteFunction

1.2.2.4.1 EndProperty

1.2.3 functionimportmapping function Import mappings. In the Functionimportname conceptual model, if the mapped function is imported. functionname function names in the storage model

1.2.3.1 resultmapping return type mapping

1.2.3.1.1 EntityTypeMapping

1.2.3.1.2 complextypemapping

Iv. LINQ to Entities 1. Process
    1. Constructs a objectquery (T) instance from ObjectContext.

    2. Write a LINQ to Entities query in C # by using an instance of ObjectQuery (T).

    3. Converts the LINQ standard query operators and expressions to the command tree.

    4. A query that executes a command tree representation on the data source. Any exceptions that are raised on the data source during execution are passed directly up to the client.

    5. Returns the results of the query to the client.

One of the three core contents of programming: Data processing

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.