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 ~~