Model view controller MVC LINQ:找不到源类型“X”的查询模式的实现选择“未找到”
刚开始搞乱存储库/接口之类的东西时,我在选择一条无法计算的记录时出现了一个错误 我的控制器有:Model view controller MVC LINQ:找不到源类型“X”的查询模式的实现选择“未找到”,model-view-controller,linq-to-sql,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
public ViewResult Detail(int ID)
{
var Details = (from x in repo.GetBreakdown(ID) select new BreakdownDetailViewModel { }).SingleOrDefault();
return View(Details);
}
语句repo.GetBreakdownID带下划线,出现以下错误:
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; }
}
}
对这里的问题有什么想法吗
谢谢,
克里斯根据@Evan的评论 已将我的存储库访问权限更改为:
public IEnumerable<tblBreakdown_Log> GetBreakdown(int ID)
{
return (from x in db.tblBreakdown_Logs where x.MB_ID == ID select x);
}
现在一切按需工作=]从repo.GetBreakdownID中的x开始??类型为IEnumerable的tblBreakdown_日志吗?源代码中的x,其中源代码需要实现IEnumerable。对于您的示例,您应该能够在repo.GetAllBreakdowns选择中从x执行操作。。。。我想通过你的评论解决了这个问题。
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);
}