I have the following table:
I have several arrays, where I will scroll if the data match to decrease its amount:
//DISMINUYE CANTIDAD DE CASILLER
public void disminuyeCasiller(string[] codParte, string [] rolls, double[] cantResta)
{
int size = codParte.Length;
for(int i = 0; i < size; i++)
{
string parte = codParte[i];
string rol = rolls[i];
double valorRes = cantResta[i];
using(var ctx=new ModelContext())
{
Casiller updateRollo = ctx.Casillers.Where(x => x.cod_parte == parte && x.rollo == rol).First();
double newValue = updateRollo.cantidad - valorRes;
updateRollo.cantidad = newValue;
ctx.SaveChanges();
}
}
}
According to what this code does, it is first to know what size the arrangements are (all the arrays will have the same size), create a for
and get the amount if the rollo
and the cod_parte
match, to that amount you recover in this case 300
will be subtract what arrives in cantResta
for example 100.50
, once subtraction is assigned in the place it was, save the changes and repeat if necessary, until there everything is fine.
I am passing this data:
codparte[]=new array{"11155"};
rollos[]=new array{"RT0102"};
cantRest[]=new array{100.50};
//Size and data can be different -only a example
at the end of cantidad
with rollo RT0102
in the table I should stay like this: 199.50
, the problem is that update both records and it looks like this:
Why also update RT0103
when this row is not being selected? What am I doing wrong in the sentence? (can be a problem in the future cuz many rollos
has the same information)
SCREENSHOT BREAKPOINT