none
SQL stored procedures from Entity Framework Core RRS feed

  • Question

  • For a portal development, we are using Angular 8 UI and .NET Core with EF as middleware and Azure SQL DB for back-end.

    Is there a way stored proc can be invoked from EF without having to have the stored proc return an entity? e.g. all the articles we are checking seem to indicate something like below,

    var products = context.Products.FromSql($"GetProducts {category}").ToList();

    in this case, is it necessary to have a "Products" entity (context.Products) available in DB for this statement to work?

    We will have around 25-30 (or more than that) stored procs in the application which will be dealing with more than 2-3 tables at a time and doing some complex calculations. With that being the case, it will be difficult to have 25-30 such entities (dummy) created in DB for each stored proc.

    Is there a different way to achieve stored proc call using EF core and not having to write one entity for each stored proc like it is with ADO.NET?

    Thank you.

    p.s. - I believe I have tagged this to correct Forum and category, please correct if that is not right.

    Monday, September 16, 2019 9:50 AM

All replies

  • Hi Suhas,

    I am afraid that you can't ignore "DbContext". The EF accesses data through "DbContext". A DbContext instance represents a combination of the Unit Of Work and Repository patterns such that it can be used to query from a database and group together changes that will then be written back to the store as a unit.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 17, 2019 7:35 AM
    Moderator
  • You can use the approach described here: https://github.com/aspnet/EntityFrameworkCore/issues/1862#issuecomment-451671168 


    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Tuesday, September 17, 2019 5:03 PM