Datetime traps in linqtonhibernate

Source: Internet
Author: User

Linqtonhibernate is a great solution ~~ If you can obtain the type check during compilation, the reuse of where clauses is much faster than that of hql ~~~

For example, I have such an entity with time constraints.

Public interface iterminableentity
{
Datetime startdate {Get ;}
Datetime? Enddate {Get ;}
}

 

Then I will give the WHERE clause that implements the unified time judgment for the entities implementing this interface.

Code Public static class terminableentitydaoimpl
{
Public static expression <func <tentity, bool> dateavailable <tentity> (this commondaoimpl <tentity> Dao, datetime DT)
Where tentity: iterminableentity, ientity
{
Return entity => DT> = entity. startdate &&(! Entity. enddate. hasvalue | entity. enddate. value> DT );
}
}

 

Easy to use

Code Public iqueryable <programentity> findallbycentre (string entityname, guid centreid)
{
Return findbycentreid (entityname, centreid). Where (this. dateavailable (datetime. Now ));
}

 

An error is reported when the migration fails! Nhib.pdf. queryexception: cocould not resolve property: Value

I'm sure my object class and mapping do not have the value field ~~~ The problem must be in entity. enddate. value> DT. remove value (loss.. Net allows comparison of the possible and non-empty types!

Check the generated SQL statement.

Code Select... from tblmfsservices this _ left Outer Join tblcentres centre1 _ on this _. uidcentrekey = centre1 _. uidcentrekey where centre1 _. uidcentrekey = @ P0 and (this _. dte1_tivedate <= @ P1 and (not (1 = 1) or this _. dteceaseddate> @ P2 ))

 

Not (1 = 1) or this _. dteceaseddate> @ P2 )... What is this... I am so thundered...

Modify it again! Entity. enddate = NULL | entity. enddate> DT (lost again this time.. Net allows the ratio of the null type and null. If nhib.pdf is still used before. I really don't know about the nullables age =)

At last, a normal SQL statement is obtained, and the result is displayed as normal.

By the way, Google found that foreigners complained about the datetime in linqtonhibernate, for example, where someentity. somedatetimeproperty. date = new date (2012, 12, 21 ~~ Linqtonhibernate seems to be being improved ~~

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.