Linq2Sql 데이터 컨텍스트에서 데이터베이스를 업데이트하거나 삭제하기 위해 다시 연결해야하는 연결이 끊어진 Linq2Sql 개체 또는 키 목록이있는 경우가 종종 있습니다. 이것이 SQL이라면 WHERE
절에 IN
을 사용할 것이지만 Linq2Sql에서 무엇을 해야할지 고민하고 있습니다.Linq2Sql을 사용하여 "In"을 시뮬레이트하는 방법
public void MarkValidated(IList<int> idsToValidate)
{
using(_Db.NewSession()) // Instatiates new DataContext
{
// ThatAreIn <- this is where I am stuck
var items = _Db.Items.ThatAreIn(idsToValidate).ToList();
foreach(var item in items)
item.Validated = DateTime.Now;
_Db.SubmitChanges();
} // Disposes of DataContext
}
또는 :
public void DeleteItems(IList<int> idsToDelete)
{
using(_Db.NewSession()) // Instatiates new DataContext
{
// ThatAreIn <- this is where I am stuck
var items = _Db.Items.ThatAreIn(idsToValidate);
_Db.Items.DeleteAllOnSubmit(items);
_Db.SubmitChanges();
} // Disposes of DataContext
}
내가이 데이터베이스에 하나 개의 여행에서 수행받을 수 여기에 내가 쓰고 싶은 것이 샘플입니다? 그렇다면 어떻게? 모든 int를 데이터베이스에 매개 변수 목록으로 보낼 수 있습니까? 목록에서 foreach를 수행하는 것보다 한 번에 하나씩 각 항목을 선택하는 것이 더 효율적입니까?