简体   繁体   中英

Execute SP using Repository Pattern and MVC5

I want to execute 'Stored Procedure' using MVC 5 and Repository Pattern. 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[]) "

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)

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 . This happened for overlapping .dll inside my project. However, Clean Used & Duplicate .dll using Re-sharper isn't work for me. So, I re-create the project and after then this problem is gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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