本文介绍了CompiledQuery和Guid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个listalbum,想要使用compiledquery,代码如下: -



public List< PhotoAlbum> ListAlbum(Guid blocId)
{
using(HomeBloc2Entities hb = new HomeBloc2Entities())
{
return CompiledListAlbum(hb,blocId);
}
}



private static Func< HomeBloc2Entities,Guid,List< PhotoAlbum>> CompiledListAlbum =
CompiledQuery.Compile((HomeBloc2Entities entities,Guid blocId)=>
(来自p的实体.PhotoAlbum,其中p.BlocId == blocId选择p).ToList< PhotoAlbum>());



但是当我调用它时,它有以下错误。



LINQ to Entities无法识别方法'System.Collections.Generic.List`1 [ACI.HomeBloc2.BLL.PhotoAlbum] ToList [PhotoAlbum](系统。 Collections.Generic.IEnumerable`1 [ACI.HomeBloc2.BLL.PhotoAlbum])'方法,此方法无法转换为商店表达式。



但是,如果我不使用编译的查询,它没有任何问题。



CompiledQuery支持guid吗?



问候


Alex

解决方案

Hi All, I have a listalbum and want to use the compiledquery and the code is as follows:-

 

 public List<PhotoAlbum> ListAlbum(Guid blocId)
        {
            using (HomeBloc2Entities hb = new HomeBloc2Entities())
            {
                return CompiledListAlbum(hb, blocId);
            }
        }

 

  private static Func<HomeBloc2Entities, Guid, List<PhotoAlbum>> CompiledListAlbum=
        CompiledQuery.Compile((HomeBloc2Entities entities, Guid blocId) =>
        (from p in entities.PhotoAlbum where p.BlocId==blocId select p).ToList<PhotoAlbum>());

 

But when I call it, it has the following error.

 

LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[ACI.HomeBloc2.BLL.PhotoAlbum] ToList[PhotoAlbum](System.Collections.Generic.IEnumerable`1[ACI.HomeBloc2.BLL.PhotoAlbum])' method, and this method cannot be translated into a store expression.

 

However, it don't have any problem if I don't use the compiled query.

 

Is the guid supported under CompiledQuery?

 

Regards

Alex

解决方案


这篇关于CompiledQuery和Guid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 14:44