를 쿼리에 하나의 LINQ 내에서 두 개의 구조적으로 호환되지 않는 초기화에 표시되지만 다음과 같은 오류 가져옵니다매핑 가입 - 유형 'CarDTO은'엔티티 내가 <code>left join</code>의 오른쪽에서 <code>CarDTO</code>로 매핑하는 것을 시도하고있다
을The type 'CarDTO' appears in two structurally incompatible initializations within a single LINQ to Entities query. A type can be initialized in two places in the same query, but only if the same properties are set in both places and those properties are set in the same order.
나는 self left join
를 만들기 위해 노력하고 내 쿼리는 다음과 같습니다
var query = from left in db.Cars
join right in db.Cars on left.id_Base equals right.ID into rightGrouped
from rightGr in rightGrouped.DefaultIfEmpty()
select new CarDTO()
{
ID = left.ID,
Description = left.DisplayName,
Name = left.Name,
IsSystem = left != null ? left.Template.isSystem : (byte?)null,
IdBase = left.id_Base,
InnerCar = new CarDTO()
{
ID = rightGr.ID,
Description = rightGr.DisplayName,
Name = rightGr.Name,
IsSystem = rightGr != null ? rightGr.Template.isSystem : (byte?)null,
IdBase = rightGr.id_Base,
InnerCar = new CarDTO()
}
};
나는 다음과 같은 행을 변경하는 경우 InnerCar = new CarDTO()
InnerCar = null
에, 다음 내가 추적을 얻을 오류 :
Unable to create a null constant value of type 'CarDTO'. Only entity types, enumeration types or primitive types are supported in this context.`
아무도 내가 뭘 잘못하고 있는지 알아?
을 마지막 줄에서'InnerCar = new CarDTO()'를'InnerCar = null'으로 변경해보십시오. – Evk
@Evk 조언을 해주셔서 감사합니다. ''CarDTO '유형의 널 (NULL) 상수 값을 생성 할 수 없습니다.'오류가 발생합니다. 이 문맥에서 엔티티 타입, 열거 형 또는 기본 타입 만 지원됩니다. ' – StepUp
'InnerCar '(예 : 익명 타입 사용)에 다른 유형을 사용하는 것 외에는 다른 방법이없는 것 같습니다. – Evk