Conditional object operator overload & (and), | (OR)

Source: Internet
Author: User
I have discussed data components with my friends (hfsoft. data) condition object, which makes it inconvenient for the same condition object to construct complex conditions, and is difficult to maintain. for example, (orderid> 10600) and Order <10700) or (orderid> 10800 and orderid <10900), constructing conditional objects is not intuitive and difficult to maintain in the future. this complex SQL condition is often encountered during development! In this case, the condition object will Program Worse! Later, he made a comment on whether the condition object can be added with Operator Overloading and sent to the related technical application website.
After reading the information, I knocked on my head. I didn't even think of it (I didn't have a good foundation !), Conditional objects are much more convenient and concise to use after being overloaded with operators. the preceding condition example overload the query object expression :( (exp1 & exp2) | (exp3 & exp4 )). the expected results are unexpected. The operator overload is really an error-free function. Unfortunately, I have never thought of it before!
(Orderid> 10600) and Order <10700) or (orderid> 10800 and orderid <10900) or employeeid = 1
Query by condition object Code As follows:
Using (hfsoft. Data. idatasession session = hfsoft. Data. mappingcontainer. configcontainer. opensession ())
{
Expression exp1 = expressionfactory. RT ("orderid", 10600) & expressionfactory. Le ("orderid", 10700 );
Expression exp2 = expressionfactory. RT ("orderid", 10800) & expressionfactory. Le ("orderid", 10900 );
Session. open ();
System. Collections. ilist list = session. List (typeof (northwind. entitys. Orders), (exp1 | exp2) | expressionfactory. eq ("employeeid", 1 ));
This. Maid = List;
}
Case code

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.