Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi can i get some hel please.
i have error at the line where try to compare to Guid

thank you


C#
<pre> [HttpDelete("{id}")]
        public async Task<ActionResult<StockTranfert>> DeleteStockTranfert(Guid id)
        {
            var stockTranfert = await _context.StockTranfert.FindAsync(id);
            var stockTransfertDtail = await _context.StockTransfertDetail.Where(w => w.StockTransfertId == id);


            if (stockTranfert == null)
            {
                return NotFound();
            }

            _context.StockTranfert.Remove(stockTranfert);
            _context.StockTransfertDetail.Remove(stockTransfertDtail);

            await _context.SaveChangesAsync();

            return stockTranfert;
        }


What I have tried:

i have try to equals fonction to compare but it same, i have try to convert the two values in string before comparing, it's same.

after that when i get the line , i want to remove it in this line
_context.StockTransfertDetail.Remove(stockTransfertDtail);
Posted
Updated 14-Apr-20 2:38am
v2

1 solution

If you want us to help you fix an error, then you need to tell us what your error is.

At a guess, you're getting an error on the var stockTransfertDtail line because you're trying to await something which isn't awaitable. The Where extension method returns an IQueryable<T>, not a Task<T>. You need to add .ToListAsync() to that line:
C#
var stockTransfertDtail = await _context.StockTransfertDetail.Where(w => w.StockTransfertId == id).ToListAsync();
However, it's not clear why you're loading that list, since you're not doing anything with it.

If that's not the problem, then you need to update your question to include the full details of the error you're getting.
 
Share this answer
 
Comments
Member 13220552 14-Apr-20 8:39am    
thanks Richard Deeming , i have done , after i juste want to delete the line , i have updated my question ,

i want to delete some data who have foreign key in StockTransfertDetail that is my problem ,

when i do your answer ,

i have error in
_context.StockTransfertDetail.Remove(stockTransfertDtail);
Richard Deeming 14-Apr-20 8:41am    
Again, if you want someone to help you fix an error, you need to tell us what the error is.

At a guess, you're trying to pass a list of objects to a method which only accepts a single object. Depending on which version of Entity Framework you're using, you'll either need to call RemoveRange, or iterate through the list and Remove each item.
Member 13220552 14-Apr-20 11:27am    
for the error , i will share next time , thank you Richard .
for me when i mean the line is enough.

thanks you for your response

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900