MVC LINQ:无法找到源类型' X'的查询模式的实现。 '选择'未找到

时间:2012-12-19 15:52:16

标签: model-view-controller linq-to-sql

刚开始搞乱使用存储库/接口等,我在选择单个记录时遇到错误,我无法解决。

我的控制器有:

    public ViewResult Detail(int ID)
    {
        var Details = (from x in repo.GetBreakdown(ID) select new BreakdownDetailViewModel { }).SingleOrDefault();

        return View(Details);
    }

语句repo.GetBreakdown(ID)带下划线,出现以下错误:

Could not find an implementation of the query pattern for source type ''. 'Select' not found.

我的界面显示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Entities;

namespace Domain.Abstract
{
    public interface IBreakdownRepository
    {
        tblBreakdown_Log GetBreakdown(int ID);
        IQueryable<tblBreakdown_Log> GetAllBreakdowns { get; }

    }
}

存储库本身有:

 public tblBreakdown_Log GetBreakdown(int ID)
        {
            return (from x in db.tblBreakdown_Logs where x.MB_ID == ID select x).SingleOrDefault();
    }

关于这个问题的任何想法?

谢谢, 克里斯

1 个答案:

答案 0 :(得分:0)

根据@Evan的评论

将我的存储库访问权限更改为:

    public IEnumerable<tblBreakdown_Log> GetBreakdown(int ID)
        {
            return (from x in db.tblBreakdown_Logs where x.MB_ID == ID select x);
        }

存储库的界面现在具有:

 IEnumerable<tblBreakdown_Log> GetBreakdown(int ID);

我的控制器访问权限是:

 public ViewResult Detail(int ID)
        {
        var Details = (from x in repo.GetBreakdown(ID) select new BreakdownDetailViewModel {Machine_Status=x.tblMachine_Status.Machine_Status, MB_ID=x.MB_ID});

        return View(Details);
    }

现在根据需要工作=]