전 세계화를 제품 카탈로그에 추가하기 위해 노력하고 있습니다. 그러나, 나는 underlaying SQL 쿼리뿐만 아니라 그것을 수행 할 수 있고 더 효율적으로 내 Linq To SQL 쿼리를 변경하는 방법에 대한 몇 가지 조언이 필요할 수 있다고 생각합니다.Linq to SQL 쿼리를 최적화하여 여러 하위 쿼리 (조인을 포함) 제거에 대한 조언
제품을 사용
표는 각 제품에 대한 고유 ID가 포함되어 있습니다. 이 열의 이름은 EntityID
입니다. TextTranslation에는 세계화 된 텍스트가 들어 있습니다. 이 테이블의 열은 CultureID (문자열), TextID (텍스트 참조), Value (세계화 된 실제 텍스트)입니다.
텍스트에는 세계화 된 텍스트와 제품 간의 매핑이 포함되어 있습니다.
텍스트 유형에는 텍스트 유형에 대한 정의 (ID, 이름 및 설명)가 들어 있습니다. 텍스트 유형을 나타내는 열도 있습니다 (이름, 설명 등).
var culturedTexts =
from translation in ctx.TextTranslations
join text in ctx.Texts on translation.TextId equals text.TextId
where translation.CultureId == "en-EN"
select new
{
text.EntityId,
text.TextTypeId,
translation.Value,
};
var products =
from p in ctx.Products
let texts = culturedTexts.Where(i => i.EntityId == p.EntityId)
select new Model.Product
{
Description = texts.Where(c => c.TextTypeId == (int)TextType.Description).SingleOrDefault().Value,
Name = texts.Where(c => c.TextTypeId == (int)TextType.Name).SingleOrDefault().Value
};
이 실행되면 나는
SELECT (
SELECT [t1].[Value]
FROM [Common].[TextTranslation] AS [t1]
INNER JOIN [Common].[Text] AS [t2] ON [t1].[TextId] = [t2].[TextId]
WHERE ([t2].[TextTypeId] = 2) AND ([t2].[EntityId] = [t0].[EntityId]) AND ([t1].[CultureId] = 'sv-SE')
) AS [Description], (
SELECT [t3].[Value]
FROM [Common].[TextTranslation] AS [t3]
INNER JOIN [Common].[Text] AS [t4] ON [t3].[TextId] = [t4].[TextId]
WHERE ([t4].[TextTypeId] = 1) AND ([t4].[EntityId] = [t0].[EntityId]) AND ([t3].[CultureId] = 'sv-SE')
) AS [Name]
FROM [Catalog].[Product] AS [t0]
는 그래서 LINQ 쿼리의 각 세계화 텍스트 (이름, 설명) 자신의 서브 쿼리를 얻고 가입 관련과 같은 쿼리를 얻을. 이것이 조금 간소화하고 각 텍스트 유형을 제거하여 자체 조인과 하위 쿼리를 가져올 수 있습니까?