简体   繁体   English

使用存储库模式和MVC5执行SP

[英]Execute SP using Repository Pattern and MVC5

I want to execute 'Stored Procedure' using MVC 5 and Repository Pattern. 我想使用MVC 5和存储库模式执行“存储过程”。 I write code for it but it give me error like 我为此写代码,但它给我类似的错误

" Method not found: 'System.Collections.Generic.IEnumerable`1 System.Data.Entity.Database.SqlQuery(System.String, System.Object[]) " 找不到方法:'System.Collections.Generic.IEnumerable`1 System.Data.Entity.Database.SqlQuery(System.String,System.Object [])

My Interface 我的介面

public interface IMemberRepository
{
   IEnumerable<MemberDetails> GetAll(); 
 }

Repository 资料库

public class MemberRepository : IMemberRepository
{
    ChatDBEntities entities = new ChatDBEntities(); // DB Entity which is generate by DB First Approach (EDMX)

    public IEnumerable<MemberDetails> GetAll()
    {
        string SP_SQL = "[GetMemberDetails]";
        var list = entities.Database.SqlQuery<MemberDetails> 
              (SP_SQL).ToList<MemberDetails>();
        return list;
    }
}

API Call ( Error given at the time of call repository from API) API调用(从API调用存储库时给出错误

public class MemberController : ApiController
{
    static readonly IMemberRepository repository = new MemberRepository();
    public IEnumerable GetAll()
    {
        return repository.GetAll();
    }
}

Please someone help me to find out a way to solve this problem. 请有人帮助我找出解决此问题的方法。

I just solve this problem. 我只是解决这个问题。 Actually this is an MissingMethodException . 实际上,这是MissingMethodException This happened for overlapping .dll inside my project. 我的项目中重叠的.dll发生了这种情况。 However, Clean Used & Duplicate .dll using Re-sharper isn't work for me. 但是,使用Re-sharper清除Clean Used&Duplicate .dll对我不起作用。 So, I re-create the project and after then this problem is gone. 因此,我重新创建了项目,然后此问题消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM