我得到的错误是
错误1'OCDSandbox.Models.OrganizationRepository'未实现 接口成员 'OCDSandbox.Models.IRepository.FindByOrgNbr()'C:\ source temp \ OCDSandbox \ OCDSandbox \ Models \ OrganizationRepository.cs第9行
OrganizationRespository.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace OCDSandbox.Models
{
public class OrganizationRepository : IRepository
{
private GMS_Sandbox_testDataContext _dataContext;
public OrganizationRepository()
{
_dataContext = new GMS_Sandbox_testDataContext();
}
public IList<Organization> ListAll()
{
var organizations = from o in _dataContext.Organizations
select o;
return organizations.ToList();
}
public ICollection<Organization> FindAll()
{
return _dataContext.Organizations.ToList();
}
public ICollection<Organization> FindByOrgNbr(string OrgNbr)
{
var organizations = _dataContext.Organizations.Where(p => p.org_nbr == OrgNbr).ToList();
return organizations;
}
}
}
IRepository.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace OCDSandbox.Models
{
public interface IRepository
{
// organization interface
IList<Organization> ListAll();
ICollection<Organization> FindAll(); //returns list read only
ICollection<Organization> FindByOrgNbr();
}
}
非常感谢任何帮助。这是我第一次使用repo,然后我想在控制器中测试FindByOrgNbr。提前谢谢!
答案 0 :(得分:3)
您在FindByOrgNbr
的定义中缺少接口中的参数using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace OCDSandbox.Models
{
public interface IRepository
{
// organization interface
IList ListAll();
ICollection FindAll(); //returns list read only
ICollection FindByOrgNbr(string OrgNbr);
}
}
答案 1 :(得分:0)
谢谢,因为界面有以下方法:ICollection<Organization> FindByOrgNbr();
,您的班级有public ICollection<Organization> FindByOrgNbr(string OrgNbr)
界面似乎也需要OrgNbr参数。
答案 2 :(得分:0)
您在OrgNbr
的接口定义中缺少FindByOrgNbr()
参数。
public interface IRepository
{
// organization interface
IList<Organization> ListAll();
ICollection<Organization> FindAll(); //returns list read only
ICollection<Organization> FindByOrgNbr(string OrgNbr);
}