내가, 내가 오류를 내가 그것을 구축 할 때 CommunicationExtension
하위 쿼리IQueryable 전체 트리를 필터링하는 방법?
static class Program
{
public class Contact
{
public int ContactID { get; set; }
public List<Communication> Communications { get; set; }
public DateTime? DeletionDate { get; set; }
}
public class Communication
{
public int CommuncationID { get; set; }
public List<CommunicationExtension> CommunicationExtensions { get; set; }
public DateTime? DeletionDate { get; set; }
}
public class CommunicationExtension
{
public int CommunicationExtensionID { get; set; }
public int AreaCode { get; set; }
public DateTime? DeletionDate { get; set; }
}
static void Main(string[] args)
{
IQueryable<Contact> q = GenerateData();
IQueryable<Contact> result =
q.Where(c => c.DeletionDate == null &&
c.Communications.Where(co => co.DeletionDate == null &&
co.CommunicationExtensions.Where(ce => ce.DeletionDate == null));
}
private static IQueryable<Contact> GenerateData()
{
return new List<Contact>
{
new Contact
{
ContactID = 1,
DeletionDate = DateTime.Now,
Communications =
new List<Communication>
{
new Communication
{
CommuncationID = 1,
DeletionDate = DateTime.Now,
CommunicationExtensions =
new List<CommunicationExtension>
{
new CommunicationExtension
{
CommunicationExtensionID = 1,
AreaCode = 5,
DeletionDate = null
}
}
},
new Communication
{
CommuncationID = 2,
DeletionDate = null,
CommunicationExtensions =
new List<CommunicationExtension>
{
new CommunicationExtension
{
CommunicationExtensionID = 2,
AreaCode = 55,
DeletionDate = DateTime.Now
}
}
}
}
},
new Contact
{
ContactID = 2,
DeletionDate = null,
Communications =
new List<Communication>
{
new Communication
{
CommuncationID = 1,
DeletionDate = null,
CommunicationExtensions =
new List<CommunicationExtension>
{
new CommunicationExtension
{
CommunicationExtensionID = 3,
AreaCode = 54,
DeletionDate = null
}
}
},
new Communication
{
CommuncationID = 2,
DeletionDate = DateTime.Now,
CommunicationExtensions =
new List<CommunicationExtension>
{
new CommunicationExtension
{
CommunicationExtensionID = 4,
AreaCode = 5565,
DeletionDate = null
}
}
}
}
}
}.AsQueryable();
}
}
을 포함 Communication
하위 쿼리가 포함 Contact
쿼리를 얻을 수있다 :
운영자에 적용 할 수 없습니다 '&가 &' 라인 형 'System.Collections.Generic.IEnumerable' '부울'와
의 피연산자 :
IQueryable<Contact> result =
q.Where(c => c.DeletionDate == null &&
c.Communications.Where(co => co.DeletionDate == null &&
co.CommunicationExtensions.Where(ce => ce.DeletionDate == null)));
삭제되지 않은 모든 데이터를 필터링해야합니다 (DeletionDate == null
). 내 시나리오에서는 데이터베이스 ~ 200 개 테이블이 각 테이블이 여기에 널 (NULL) 필드 DeletionDate
삭제되지 않은 모든'Contacts'''''''''와'CommunicationExtensions''을 원합니다. 이러한 관련 테이블은이 예에서와 같이 3 개를 초과 할 수 있습니다. 그리고 여러 개의'Where()'에 이것을 써야합니다. 불필요한 모든 데이터를로드하기 때문에'ToList()'를 사용할 수 없습니다. 나중에이 데이터는 단일 '연락처'를보기 위해 바인드됩니다. '통신'또는 'CommunicationExtensions'에서 필요로 할 때 더 많은 데이터가로드됩니다. –