티스토리 뷰
DB를 한번 다녀온 리스트 컬렉션에 대해서
LINQ(링큐) 문을 이용해서 다시 재가공 하는 방법
일반적으로 아는 방법으로 해도 상관없으나
다시 리스트형식이나 ToArray() 방식으로 받으려면
anonymous types (익명형식에 맞지 않습니다) 라는 에러가 발생하거나, 그외 잡다한 익명타입 관련 에러가 발생하는 경우가 있다. 아래 방법1, 2처럼 사용하면 LINQ 에서도 LIST나 다른 Collection 객체로 받을 수 있다.
public class Organizational
{
public string DeptLv1_Code { get; set; }
public string DeptLv1_Name { get; set; }
public string DeptLv2_Code { get; set; }
public string DeptLv2_Name { get; set; }
public string DeptLv3_Code { get; set; }
public string DeptLv3_Name { get; set; }
public string Person_Code { get; set; }
public string Person_Name { get; set; }
public string Person_Photo { get; set; }
public int Disp_Seq { get; set; }
}
방법1.
IEnumerable<Organizational> orgItem = from p in OrgList
where p.DeptLv3_Code == cntPolitc[i]
orderby p.Disp_Seq
select new Organizational { DeptLv1_Code = p.DeptLv1_Code, DeptLv1_Name = p.DeptLv1_Name, DeptLv2_Code = p.DeptLv2_Code, DeptLv2_Name = p.DeptLv2_Name, DeptLv3_Code = p.DeptLv3_Code, DeptLv3_Name = p.DeptLv3_Name, Disp_Seq = p.Disp_Seq, Person_Code = p.Person_Code, Person_Name = p.Person_Name, Person_Photo = p.Person_Photo };
방법2
List<Organizational> orgItem = (from p in OrgList
where p.DeptLv3_Code == cntPolitc[i]
orderby p.Disp_Seq
select new Organizational { DeptLv1_Code = p.DeptLv1_Code, DeptLv1_Name = p.DeptLv1_Name, DeptLv2_Code = p.DeptLv2_Code, DeptLv2_Name = p.DeptLv2_Name, DeptLv3_Code = p.DeptLv3_Code, DeptLv3_Name = p.DeptLv3_Name, Disp_Seq = p.Disp_Seq, Person_Code = p.Person_Code, Person_Name = p.Person_Name, Person_Photo = p.Person_Photo }).ToList();
'프로그래밍 > ASP.NET' 카테고리의 다른 글
네트워크 사용 가능 상태 확인 (0) | 2012.11.15 |
---|---|
DataBinding <%# %> 데이터 바인딩 (0) | 2012.11.07 |
C# SMTP 대량메일 보내기 (0) | 2012.10.23 |
Ajax - Web Services 호출 (0) | 2012.10.08 |
ASP.NET PageMethods와 JSON을 통한 다이나믹 페이지 개발 (0) | 2012.10.05 |
- Total
- Today
- Yesterday
- CSS
- 프로시저
- jquery chart
- 제이쿼리
- ASP.NET
- 셀렉터
- Ajax
- JavaScript
- rowspan
- jQuery
- grid
- WCF
- SVG
- 저장프로시저
- IE
- Excel
- Style
- Mobile
- 자바스크립트
- workbook
- Chart
- css3
- MSSQL
- radius
- html5
- jQuery Mobile
- json
- WebApi
- drag&drop
- JS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |