Execute stored procedure using entity framework

前端 未结 4 761
鱼传尺愫
鱼传尺愫 2020-12-29 15:43

is it possible to execute a stored procedure using EF, that select records from database from two or more tables using inner join and left outer join.

my point of vi

4条回答
  •  遥遥无期
    2020-12-29 16:29

    You can call SqlQuery from your Entity Framework data context.

    context.Database.SqlQuery("exec usp_StoredProcedure").ToList()
    

    You would need a class to map the query results back, as an example:

    public class YourType
    {
       public string Property1 { get; set; }
       public string Property2 { get; set; }
    }
    

    You can also specify parameters to the query as shown below:

    SqlParameter parameter1 = new SqlParameter("@Parameter1", "Value");
    context.Database.SqlQuery("exec usp_StoredProcedure @Parameter1", parameter1).ToList()
    

提交回复
热议问题