能用LinqToNhibernate还是很爽的~~能获得编译时类型检查就不说了,就连where子句的复用都比用HQL爽快很多~~~

比如我有这种有时间限制的实体

    public interface ITerminableEntity
    {
        DateTime StartDate { 
get; }
        DateTime
? EndDate { get; }
    }

 

然后我给实现这种接口的实体统一实现时间判断的where子句

    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);
        }
    }

相关文章:

  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2022-02-28
  • 2021-07-23
  • 2022-12-23
  • 2021-08-25
猜你喜欢
  • 2021-08-18
  • 2021-06-29
  • 2021-07-02
  • 2021-04-28
  • 2021-07-08
  • 2021-12-19
  • 2022-01-30
相关资源
相似解决方案