实体框架4.1 code首先 - 包括正在使用时,忽略LinqKit predicateBuilder实体、框架、predicateBuilder、LinqKit

由网友(谁许我至死不渝的爱情╮谁给我白头偕老的爱情╮)分享简介:我使用C首先实体框架4.1 $ C $,并使用predicateBuilder这样我就可以建立predicate EX $ P $多个规范类(使用规范模式)pssions我。我能够正确地构建predicate并将其应用到一个DbSet,而我得到的数据是我所期望的。但是,不管我怎么努力,总是懒加载。这就是我如何建立pre...

我使用C首先实体框架4.1 $ C $,并使用predicateBuilder这样我就可以建立predicate EX $ P $多个规范类(使用规范模式)pssions我。我能够正确地构建predicate并将其应用到一个DbSet,而我得到的数据是我所期望的。但是,不管我怎么努力,总是懒加载。这就是我如何建立predicate并将其应用于一个简单的例子。

I am using Entity Framework 4.1 Code First and am also using the PredicateBuilder so that I can build predicate expressions across multiple Specification classes (using the Specification pattern). I am able to properly build a predicate and apply it to a DbSet, and the data I get is what I expect. However, no matter what I try, it's always lazy loading. This is a simple example of how I'm building the predicate and applying it.

IQueryable<HairColor> hairColorQuery = Context.Set<HairColor>().AsExpandable();

Expression<Func<Parent, bool>> parentPredicate = PredicateBuilder.And(PredicateBuilder.True<Parent>(), p => p.NameLast.StartsWith("V")).Expand();

Expression<Func<HairColor, bool>> hairColorPredicate = PredicateBuilder.And(PredicateBuilder.True<HairColor>(), h => h.Parents.AsQueryable().Any(parentPredicate));

HairColor[] hairColors = hairColorQuery.Where(hairColorPredicate).Include(h => h.Parents).ToArray();

就像我上面说的,我得到了我想要的数据背后,却忽略了包括

Like I said above, I'm getting the data back that I want, but it ignores the Include.

有没有人有什么想法?

推荐答案

使用LinqKits时predicate建设者跳跃在后期这个喜,但使用扩展有同样的问题包括法。如在previous答案提到的问题是,铸造LinqKits ExpandableQuery到的ObjectQuery(所要求的包括扩展名)的结果在空。

Hi jumping in late on this, but had the same issue with using an extension Include method when using LinqKits predicate builder. The problem as referred to in the previous answer is that casting LinqKits ExpandableQuery to ObjectQuery (as required by the Include extension) results in null.

但是发现这个链接http://petemontgomery.word$p$pss.com/2011/02/10/a-universal-$p$pdicatebuilder/其是predicate助洗剂不使用AsExpandable执行搜索,因此包含方法可以在其上使用。尽管上述解决方案也为我工作这两样predicate建设者让我保持我的code清洁/更稳定的

However found this link http://petemontgomery.wordpress.com/2011/02/10/a-universal-predicatebuilder/ which is a Predicate builder which doesn't use AsExpandable to perform the search and hence the Include method can be used on it. Although the solution above also worked for me this different predicate builder allowed me to keep my code cleaner/more consistent

阅读全文

相关推荐

最新文章