簡體   English   中英

在實體框架中的存儲過程上使用IQueryable

[英]Use IQueryable on stored procedure in Entity Framework

我試圖在存儲過程上使用IQueryable ,編寫存儲過程的原因是要檢查查詢中的多個條件。 如果我走錯了方向,請指正我。

我假設應用IQueryable將比IEnumerable快得多,不要忘記我能夠在其他實體上使用IQueryable而沒有任何問題。

控制器:

public ActionResult CrmBlogGroupType(int? page, bool? Name, bool? AuthorTitle, bool? Description, string search, int? PageSize, string type)
{
    try
    {
        if (type==null)
        {
            type = "A";
        }

        IQueryable<Usp_getBlogSetPosts_Result> _objBlogSet = _dataLayer.GetBlogSet(type);
        var Result = _objBlogSet.ToPagedList(page ?? 1, PageSize ?? 10);

        return View(_objBlogSet);
}

數據層:

public IQueryable<Usp_getBlogSetPosts_Result> GetBlogSet(string type)
{
        IQueryable<Usp_getBlogSetPosts_Result> Obj = _dbContext.Usp_getBlogSetPosts(type).AsQueryable();
         return Obj;
}

Context.cs

 public virtual ObjectResult<Usp_getBlogSetPosts_Result> Usp_getBlogSetPosts(string blogSetType)
 {
        var blogSetTypeParameter = blogSetType != null ?
            new ObjectParameter("BlogSetType", blogSetType) :
            new ObjectParameter("BlogSetType", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Usp_getBlogSetPosts_Result>("Usp_getBlogSetPosts", blogSetTypeParameter);
}

錯誤:

查詢結果不能被多次枚舉

這是因為存儲過程輸出結果集的類型不是IQueryable ..您必須使用IEnumerable才能運行存儲過程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM