ループ内でデータベース内の一部のデータの値を変更するコードがあります。最初にデータをフィルタリングする最も効率的な方法は何ですか? 例を挙げます:-
クラスで: -
public class myObj
{
int id {get;set;}
string product {get; set;}
string parent{get;set;}
bool received {get;set;}
}
そしてDbContext:-
public class myCont:DbContext
{
public DbSet<myObj> myObjs {get;set;}
}
これを行う方が良いですか:-
int[] list;
/* Populate list with a bunch of id numbers found in myOBjs */
myCont data = new myCont();
myObj ob = data.myObjs.Where(o => o.parent == "number1");
foreach(int i in list)
{
ob.First(o => o.id == i && o.received != true).received = true;
}
または:-
int[] list;
/* Populate list with a bunch of id numbers found in myOBjs */
myCont data = new myCont();
foreach(int i in list)
{
data.myObjs.First(o => o.parent == "number1" && o.id == i && o.received != true).received = true;
}
それとも違いはありませんか?