다른 사람이이 질문을 던졌을 것이라고 확신하지만 해결책을 찾기 위해 무엇을 생각할 수 있는지 검색했습니다.Linq를 사용하여 여러 테이블에서 읽기
I했습니다 내 SQL의 DB에 테이블을 일치하도록 다음과 같은 데이터 모델을 가지고 :
public class ProfileDetailModel
{
public string id { get; set; }
public string name { get; set; }
public StyleList[] styleList { get; set; }
public FabricList[] fabricList { get; set; }
}
public class StyleList
{
public string id { get; set; }
public string name { get; set; }
}
public class FabricList
{
public string id { get; set; }
public string fabricName { get; set; }
}
이 현재 쿼리 코드 : 스타일과 원단 아래
var query = (from t in db.tblProfiles
select new ProfileDetailModel()
{
id = t.id,
name = t.name
});
var querylist = await query.ToListAsync();
(프로토 타입 LINQ 쿼리)
var styleQuery = (from t in db.tblStyles
select new styleList()
{
id = t.id,
name = t.name
});
var fabricQuery = (from t in db.tblFabrics
select new fabricList()
{
id = t.id,
name = t.name
});
if (queryList.Count > 0)
{
var item = queryList[0];
item.styleList = styleQuery;
item.fabricList = fabricQuery;
}
하나의 profileDetailModel에 styleList와 fabricL의 여러 항목이 있습니다. ist. EG.
ProfileDetailModel
데이터 : 바지
styleList : 벨 바닥, 직선 다리, 부팅에 맞게
fabricList : 진 블루, 진 - 블랙, 체크 무늬
위의 세 모델은 모두 내 데이터베이스에있는 테이블입니다. 필자는 데이터를 읽기 위해 세 가지 별도의 쿼리를 실행할 수 있습니다. 하지만 한 번에 기본 쿼리에서 두 배열을 포함하도록 linq 쿼리를 수행 할 수있는 방법이 있습니까?
에서, ProfileDetailModel 그래서 난 중복이있을 것이다 StyleList 및 패브릭 목록의 각 항목에 대한 목록이 표시됩니다. 많은 styleList 및 fabricList에 대해 하나의 ProfileDetailModel이 있습니다. 나는 그 질문을 수정하여 – DaBlue
을 포함 할 것입니다. 따라서 linq은 데이터 액세스와 아무 관련이 없습니다 ... [tag : entity-framework] 또는 [tag : linq2sql]입니까? –
하늘빛 플랫폼의 엔티티 프레임 – DaBlue