locked
Stored procedure the second time that is called does not update the data with entity framework .net core RRS feed

  • Question

  • User433211055 posted

    Hi,

    I have a service class that use a entity framwork for call a strored procedure with "FromSqlRaw" method.

    All work fine a first time, but in second time doesn't work the chipsReport array it is not update with new result.

    The parameters that I pass change

    This is my method with stored procedure.

    ChipReport[] chipsReport;
    
     public async Task<ChipReport[]> GetChipsReportsAsync(DateTime gamingDate, int valueTypeId, int absolute)
            {
                var param = new SqlParameter[]
                {
                    new SqlParameter() {ParameterName = "@gaming", SqlDbType = System.Data.SqlDbType.DateTime, Direction = System.Data.ParameterDirection.Input, Value = gamingDate },
                    new SqlParameter() {ParameterName = "@valuetypeid", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Input, Value = valueTypeId },
                    new SqlParameter() {ParameterName = "@absolute", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Input, Value = absolute}
                };
    
                chipsReport = _context
                              .chipsReports
                              .FromSqlRaw("EXEC [Accounting].[usp_ChipsReportEx] @gaming, @valuetypeid, @absolute", param)
                              .ToArray();
    
                await Task.Yield();
                return chipsReport;
            }

    Can anyone help me?

    BR

    Tuesday, October 6, 2020 6:23 PM

All replies

  • User753101303 posted

    Hi,

    Which wrong behavior do you see? It is supposed to update rows and return updated rows but the final array is empty?

    I would start by testing my SP with the EXACT same parameters. 

    Tuesday, October 6, 2020 6:39 PM
  • User433211055 posted

    I expect the stored procedure to give me updated data at each call with different parameters, that is, if I run the stored procedure in SQL management studio.

    So my array have always the same data.

    And as if the stored procedure were successfully executed only once.

    Tuesday, October 6, 2020 8:08 PM
  • User-189459990 posted

    What is the specific content of your stored procedure?

    Since your first execution succeeded,  this problem is not be caused by "FromSqlRaw".<o:p></o:p>

    I suggest you add a breakpoint where you call “GetChipsReportsAsync” to check whether the parameters inside have changed.<o:p></o:p>

    Wednesday, October 7, 2020 7:21 AM
  • User753101303 posted

    You tested with the SAME parameters? For now my understanding is that all happens as if an UPDATE statement doesn't work so I would make sure it works (for example using @@ROWCOUNT) with the same pararemeters or just show its content so that we can see a possible issue.

    If not that you could then  move to what make your think on the web server side that the UPDATE doesn't work etc... Debugging is not just reading code but also to check what your code does and "closing doors" which usually allow to narrow down the exact problem in few steps. Once the problem is known it is usually easy to fix.

    Edit: helped once someone with an  INSERT problem.. Past obvious issues (code not called, hidden exception), I asked him to show the number of inserted rows which showed it was working perfectly. He later found test code that deleted newly inserted rows.

    Wednesday, October 7, 2020 8:13 AM