I have recently learned some experiences in LINQ and object-oriented programming.

Source: Internet
Author: User
I have recently learned some experiences in LINQ and object-oriented programming to share with you:
1. If there are data and collections on the interface, and the data is highly real-time, you can use LINQ or wildcard lines to process the data in the memory. This reduces the query pressure on the database. The anonymous type is useful. You do not need to create many objects. Most of the tasks that SQL can do can also be done by LINQ. For example, VAR Application Form list = (from alias in Application Form set group alias by new {Department name = alias. department name, clinical department = alias. clinical Department, drug code = alias. drug Code, drug name = alias. drug name, type = alias. specification,} into G select new {G. key. department name, G. key. clinical Department, G. key. drug Code, G. key. trade_name, G. key. specification, app_num = G. sum (P => P. application Quantity * P. daily usage )}). tolist (); 2. Many of the collections we query in the system are arraylist arrays. You can convert them using the following statement: List <entity> object set = new list <entity set> (array set. toarray (). cast <entity set> ()). where (P => P. object Attributes. length> 1 ). toli St <entity> (); convert and convert to facilitate query. 3. When the attribute data volume is large, add progress bars as much as possible. 4. Enable and disable personalized requests as much as possible and can be configured automatically. The following is a code for adding parameters: // whether the private bool ispharmaceutistonly = true can be reviewed only by Pharmacy personnel (pharmacists and pharmacists; /// <summary> /// can only be reviewed by pharmacists or pharmacists /// </Summary> [description ("can only be reviewed by pharmacists or pharmacists "), category ("set"), defaultvalue (true)] public bool ispharmaceutistonly {get {return ispharmaceutistonly;} set {ispharmaceutistonly = value ;}} all the code written in the setup Field Later knows how to configure it. I will not go into detail. 5. Important: if an interface is implemented by many classes. Suddenly one day a class needs a special feature. What should we do? If you add a method to this interface, all classes that implement this interface will be implemented with an empty implementation, and the changes will be relatively large. We recommend that you create an interface so that only the classes that require this function can implement this interface. Add the previous interface. This class implements multiple interfaces. At the same time, you do not need to change to other classes. 6. How can I call an interface. There are two methods: 1. Calling through class instantiation. 2. It is called through the reflection mechanism. Note: "The interface cannot be instantiated, but an interface can be implemented through a class. If a class is instantiated, no matter how it is instantiated (including reflection), it has all the features of this class ". After understanding this sentence, it can be cleverly applied during the call: for example, A, B, C, and D are classes, IA, IB, IC, and Id are interfaces; A inherits IA; B inherits IB, IA; C inherits IC, ID, d inherits IC suddenly a wants to add a function. I added an IE interface to let a inherit from IA and IE. Because Ia functions can be implemented long ago. If you want to directly call the IE interface method. You can call it in the following way: 1. If a is previously instantiated and assigned to G 2, you can convert the G type to IE, so that you can access the IE Method. For example: interface IA = G class as interface IA; interface Ie = G class as interface ie; interface IE. method (); 3. If you try to instantiate the IE interface again, the class G may be initialized. Be careful here.

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.