Tag: 查询优化

同一个NHibernate Linq查询中的Cacheable(),FetchMany()和ToFuture()

遇到类似于以下示例的情况: 1个父实体具有2个子集合的Employee : Addresses和Phones 我需要在single roundtrip检索所有员工的初始化地址和电话,并使用Cacheable()缓存在二级缓存中实现cache the query 。 使用: var baseQuery = session .Query() .Cacheable(); baseQuery .FetchMany(e => e.Addresses) .ToFuture(); var list = baseQuery .FetchMany(e => e.Phones) .ToFuture() .ToList(); 应该工作,但我得到以下例外: NHibernate.PropertyAccessException 信息: Exception occurred getter of NHibernateTest.Objects.Entity`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Id 堆栈跟踪: at NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in p:\nhibernate-core\src\NHibernate\Properties\BasicPropertyAccessor.cs:line 213 at NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetIdentifier(Object entity) in p:\nhibernate-core\src\NHibernate\Tuple\Entity\AbstractEntityTuplizer.cs:line 139 […]

Linq2SQL“或/和”运算符(ANDed / ORed条件)

假设我们需要应用几个条件来选择一个名为“Things”的表(未知计数和性质) 如果条件已知,我们可以写 db.Things.Where(t=>foo1 && foo2 || foo3); 但是如果我们必须以编程方式构建Where条件,我可以想象我们如何应用ANDed条件 IQuerable DesiredThings = db.Things.AsQuerable(); foreach (Condition c in AndedConditions) DesiredThings = DesiredThings.Where(t => GenerateCondition(c,t)); ORed条件怎么样? 注意:我们不想执行union,unique或任何其他代价高昂的操作,我们希望生成一个查询,好像我们将它写成ad-hock 提前致谢。 加成: PredicateBuilder:动态编写表达式谓词