문제

I want to update a column of a table which got ~4k rows. The column has to get the date of the parent so I'm using a simple foreach:

Parent.VariableDate = DateTime.Now;
foreach (var item in Parent.ChildList)
{
    item.vari = Parent.VariableDate ;

}

Problem:

This action is taking ages. Can I immediately update a whole column?

도움이 되었습니까?

해결책

I'm not sure you'll gain very much from writing this any other way. A better option, if possible in your situation(?), might be to avoid using VariableDate at all in each item in ChildList, and just refer to Parent instead whenever you need it. That way, you would not have to iterate through the 4K rows at all.

As presented in your question, each item.VariableDate seems to be superfluous..

다른 팁

you can use Linq for that

Parent.ChildList.foreach(p=>p.vari = DateTime.Now);

it is the fastest way

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top