Base solution for your next web application
Open Closed

How to use Stored Procedure in asp.net core with boilerplate #3911


User avatar
0
vish created

Hi, I am using asp.net core application with abp(Asp.net BoilerPlate) framework. I want to use stored procedure to get the data and also to implement CRUD operations in this code first architecture. :roll:

What will be best way to do so? Also can I get the implementation?

Thanks in advance .

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

8 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    vish created

    Got page not found on:- <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/storedProcedureDemo">https://github.com/aspnetboilerplate/as ... cedureDemo</a>

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    vish created

    <cite>aaron: </cite>

    What will be best way to do so?

    See: Using Stored Procedure, User Defined Function and Views in a Custom Repository with ASP.NET Boilerplate

    Also can I get the implementation?

    Source code is published on Github: https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/storedProcedureDemo

    I have implemented this method shown on : Using Stored Procedure, User Defined Function and Views in a Custom Repository with ASP.NET Boilerplate . But, there they have used DataReader to read each value, I do not want to use that as it will deteriorate application performance. Is there better way to read whole data at once?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    aaron created
    Support Team

    Got page not found on:

    Fixed the link - it was an uppercase S.

    But, there they have used DataReader to read each value, I do not want to use that as it will deteriorate application performance. Is there better way to read whole data at once?

    See:

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    vish created

    Actually I want the result to be directly converted into some entity (or variable), unlike reading each and every record as it is shown on [https://www.codeproject.com/Articles/1199648/Using-Stored-Procedure-User-Defined-Function-and-V]) like this : while (dataReader.Read()) { result.Add(dataReader["UserName"].ToString()); }

    This will might hamper the performance.

    In MVC structure, we use SQlQuery() function to get the result in one statement

    var number= _context.Database.SqlQuery<int>("exec StoredProcedure@centerID", sqlCenterId).Single();

    so, is there something like this for ABP framework?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    aaron created
    Support Team

    The article shows how to call with "exec":

    public async Task DeleteUser(EntityDto input)
    {
        await Context.Database.ExecuteSqlCommandAsync(
            "EXEC DeleteUserById @id",
            default(CancellationToken),
            new SqlParameter("id", input.Id)
        );
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    vish created

    ok there they have shown for insert, update and delete, when I tried the same to fetch some data which is in the form of multiple rows and columns, I am unable to get the result. I tried like this:

    using (var command1 = CreateCommand("SelectFormFields", CommandType.StoredProcedure))
                {
                    var dataReader= (await command1.ExecuteReaderAsync());
                }
    

    & I do not want to use Read() function to read each value.

    So, I want the data to be read at once with all rows and columns ;)

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    aaron created
    Support Team
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)