SQLite databese보다 Entity Framework 4 모델이 있습니다. 모델의 일부는 다음과 같습니다. LINQ to Entities materialization 오류
모든 ID 필드에는 Guid (SQLite 테이블 DDL의 uniqueidentifier) 유형이 있습니다. 하지만 LINQ 쿼리를 실행하면 예외가 발생합니다. 내가 그것을 실행하면
var query = AbonentPfrs.Select(a =>
new
{
AbPfr = a,
Pfr = a.PfrCertificates.Select(c => c.Id),
Ac = a.AcCertificates.Select(c => c.Id)
}
);
query.ToList();
나는
System.InvalidOperationException: The type of the key field 'Id' is expected to be 'System.Guid', but the value provided is actually of type 'System.String'.
UPDATE를 얻을 : 내가 EF 정말 개체 중 하나에 대한 식별자와 같은 문자열을 반환하는 SQL 쿼리를 생성하는 것을 알아 냈다. DB를 ((query as ObjectQuery).ToTraceString())
로 이동
는 SQL은 다음과 같습니다 열에
SELECT
[UnionAll1].[C2] AS [C1],
[UnionAll1].[C3] AS [C2],
[UnionAll1].[Id] AS [C3],
[UnionAll1].[PfrRegNumber] AS [C4],
[UnionAll1].[PfrUnitId] AS [C5],
[UnionAll1].[Account_Id] AS [C6],
[UnionAll1].[ActiveCertificate_Id] AS [C7],
[UnionAll1].[C1] AS [C8],
[UnionAll1].[Id1] AS [C9],
[UnionAll1].[C4] AS [C10]
FROM (SELECT
CASE WHEN ([Extent2].[Id] IS NULL) THEN NULL ELSE 1 END AS [C1],
1 AS [C2],
1 AS [C3],
[Extent1].[Id] AS [Id],
[Extent1].[PfrRegNumber] AS [PfrRegNumber],
[Extent1].[PfrUnitId] AS [PfrUnitId],
[Extent1].[Account_Id] AS [Account_Id],
[Extent1].[ActiveCertificate_Id] AS [ActiveCertificate_Id],
[Extent2].[Id] AS [Id1],
NULL AS [C4]
FROM [AbonentPfrs] AS [Extent1]
LEFT OUTER JOIN [Certificates] AS [Extent2] ON [Extent1].[Id] = [Extent2].[AbonentPfr_PfrCertificates_Certificate_Id]
UNION ALL
SELECT
2 AS [C1],
2 AS [C2],
2 AS [C3],
[Extent3].[Id] AS [Id],
[Extent3].[PfrRegNumber] AS [PfrRegNumber],
[Extent3].[PfrUnitId] AS [PfrUnitId],
[Extent3].[Account_Id] AS [Account_Id],
[Extent3].[ActiveCertificate_Id] AS [ActiveCertificate_Id],
NULL AS [C4],
[Extent4].[Id] AS [Id1]
FROM [AbonentPfrs] AS [Extent3]
INNER JOIN [Certificates] AS [Extent4] ON [Extent3].[Id] = [Extent4].[AbonentPfr_AcCertificates_Certificate_Id]) AS [UnionAll1]
ORDER BY [UnionAll1].[Id] ASC, [UnionAll1].[C1] ASC
마지막은 인증 기관에 대한 식별자입니다. 그러나 마지막에는 Guid와 이전 문자열이 있습니다.
- 첫 번째 선택 : 다음 별도로 쿼리의 일부를 실행하면 내가 (마지막 두 FOT) 다음 열 유형을 얻을 GUID를 선택
- 두 번째 개체 : 개체의 GUID
- 연합 (EU)의 모든 : GUID를 개체
- 외부 선택 : 문자열, GUID를
왜 마지막으로 하나의 열에서 외부를 선택 반환 문자열?
나는 AbonentPfr에서 Certificates에 이르기까지 동일한 테이블에 두 개의 관계가 있다고 생각합니다. 하지만 확실하지 않다 ... – sedovav
아마 SQLite 문자열로 GUID를 저장하기 때문에? AFAIK SQLite는 기본 GUID 데이터 형식을 가지고 있지 않습니다. – okrumnow
그러나 다른 모든 쿼리에서는 corretly 작동합니다. – sedovav