creator trainer

creator trainer

  • NA
  • 3
  • 3.2k

stored procedure in sql with EF and web API

Jan 27 2018 5:02 AM
Dear Mr,
In case I need to use a stored procedure from DB in sql server and this stored procedure has many parameters and many join to many tables and return many fields from many table how to call and use it with WEB API Controller?
Many thanks and best regards,
Example : EF
public virtual DbSet<T_Clubs> T_Clubs { get; set; }
public virtual DbSet<T_Games> T_Games { get; set; }
public virtual DbSet<T_Reservations> T_Reservations { get; set; }
//HOW TO USE THIS WITH WEB API Controller this a stored procedure in DB ?!! PLease advice
public virtual int GetReservationsByClubId(Nullable<int> clubId)
{
var clubIdParameter = clubId.HasValue ?
new ObjectParameter("ClubId", clubId) :
new ObjectParameter("ClubId", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("GetReservationsByClubId", clubIdParameter);
}
//HOW TO USE THIS WITH WEB API Controller this a stored procedure in DB ?!! PLease advice
public virtual ObjectResult<GetReservations_Result> GetReservations()
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetReservations_Result>("GetReservations");
}
//HOW TO USE THIS WITH WEB API Controller this a stored procedure in DB ?!! PLease advice?
Thank you and best regards

Answers (1)