Entitymodelstudio series tutorial 5-emlib framework eql

Source: Internet
Author: User

Starting from this chapter, we will use two chapters to introduce the emlib framework. This chapter introduces eql-related content. Before introducing the eql content, you need to make preparations, that is, the configuration of the development environment, which is a very simple task.

I.Configure the development environment

Because I use vs2010, vs2010 is used as the development environment, but the content is also applicable to vs2008. First, create a new project. The language is C # And the type is Windows form application. The project name and storage directory are arbitrary. As shown in figure:

Right-click the project node and choose add-> existing item… from the shortcut menu ..., Open generateSource codeDirectory. Add the edmodel. CS file in the edmodel. biz. edextern folder first. Note that the file is referenced and added ,:

Then add the files in the edmodel. biz. edcustom folder. Note that the file is copied and added, and you can click the Add button directly, as shown in:

As shown in figure:

Then reference the dynamic link library of emlib. The emlib. dll file is in the emlib folder of the emstudio installation directory. Right-click the references node and choose add reference... from the context menu ..., Open the emstudio installation directory, open the emlib folder, and add the emlib. dll file. After adding, as shown in:

The last step is in the sourceCodeAdd a namespace to the file, open the form. CS file, add a reference to the emlib namespace in the file header, and reference the namespace where the generated source code is located, as shown in:

Now the development environment is configured.

I.EqlUse of basic statements

The full name of eql is entity model studio, a programming interface based on the host language. Allows developers to use methods for continuous calling, which is very convenient and flexible to construct statement objects of various levels of complexity. The development efficiency is significantly higher than that of traditional String concatenation to construct SQL statements. Based on the eql statement object, emlib can be used to complete all powerful ORM functions. The following is the Demo code of query, update, insert, and delete statements. You can enter the source code to construct the actual eql statement object.

Query statement:

Update statement:

Insert statement:

Delete statement:

III.From eqlSQL statement objectStatement text

Emlib directly supports obtaining equivalent text from the eql statement object, as shown in the example code:

Stmttextunit has two attributes: textwithparam, which is the equivalent text; parms, which is the parameter object used in the statement text. We can see that the above Code first generates an emcontext object to obtain the SQL text, and calls the method in mycontext. This class and method are automatically generated in the edmodel. CS file. The first parameter of this method is the location of the model file. The model file is automatically generated when the source code is generated. It is an XML file in the edmodel. biz. edextern folder. The second parameter is the emlib license file. After emstudio is registered, the file is automatically generated and located in the emlib folder of the emstudio installation directory. It is a dat file. The content of the emcontext object will be further detailed in the orm of the emlib framework in the next chapter.

You can use eqlbuildsqltext to generate equivalent texts for the preceding four statement objects, as shown below:

Query statement:

SelectCompany. ID, company. Address, company. companyName,'Company' AsCurrentitytag
FromCompanyWhereCompany. ID> @ Paramname1

Update statement:

UpdateCompanySetCompany. companyName= @ Paramname1, Company. Address= Null FromCompanyWhere Len(Company. Address)< @ Paramname2

Insert statement:

Insert IntoCompany (Company. companyName, company. Address)Values(@ Paramname1,Null)

Delete statement:

Delete company from company where Len (company. Address) <@ paramname1

4.EqlSupport for Polymorphism

The support for Polymorphism in eql is very thorough and complete. From the perspective of statement structure and ORM function, this support for polymorphism is complete. The following two examples illustrate the support for polymorphism. A more detailed introduction is completed in the next chapter. Construct the following eql statement object:

This is an eql statement object that executes multi-state queries on baseentity entities. Its equivalent text is as follows:

 Select  Baseentity. ID, baseentity. basename, baseentity. currentitytag  From (Select Baseentity. ID, baseentity. basename, '  Baseentity  '   As  Currentitytag  From Baseentity Union   All  Select Subentity. ID, subentity. basename, '  Subentity  '   As  Currentitytag From Subentity) As  Baseentity  Where Baseentity. ID >   @ Paramname1 

Construct the following deletion statement:

This indicates that the object baseentity needs to be deleted with polymorphism, that is, the qualified data of baseentity and its subclass needs to be deleted. The corresponding equivalent text is two Delete statements:

 Delete  Polysubject  From ( Select Baseentity. ID, baseentity. basename, '  Baseentity '   As  Currentitytag  From Baseentity Union   All  Select Subentity. ID, subentity. basename, '  Subentity  '   As  Currentitytag  From Subentity) As Baseentity, baseentity As Polysubject  Where Baseentity. ID >   @ Paramname1   And  Baseentity. currentitytag  =   '  Baseentity  '   And  Polysubject. ID  =  Baseentity. ID  Delete  Polysubject From ( Select Baseentity. ID, baseentity. basename, '  Baseentity  '   As  Currentitytag  From Baseentity Union   All  Select Subentity. ID, subentity. basename, '  Subentity  '   As Currentitytag  From Subentity) As Baseentity, subentity As  Polysubject  Where Baseentity. ID >   @ Paramname1   And  Baseentity. currentitytag  =   '  Subentity  '   And Polysubject. ID  = Baseentity. ID

5.Subquery

Example of a subquery:

For ease of reading and understanding, you can also split it into the following forms:

The two are completely equivalent. In this way, developers can use the eql interface to easily construct statement objects of various levels of complexity.

 

This section has all been described here, if you have any questions or need technical support to visit our website: http://www.WideUnion.com. We hope to hear your suggestions and requirements so that we can provide you with better products and services.

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.