LINQ에서 SQL 로컬라이즈 쿼리
-
23-08-2019 - |
문제
다음 테이블이 주어지면 주어진 문화에 대한 주어진 문화에 대한 현지화 된 텍스트 나 주어진 문화에 대한 행이없는 기본 문화에 대한 텍스트를 반환하고 싶습니다.
다이어그램 http://lh4.ggpht.com/_gjscwav_czc/shw6hc-eozi/aaaaaaaacby/mxabfiztby8/s400/diagram.png
따라서 Folowing 데이터와 함께
자원
ID Name
1 Donkey
2 Elephant
로컬 스트링
ID CultureID ResID LocaleText
1 1 1 Donkey
2 1 2 Elephant
3 2 1 baudet
프랑스 문화를 위해 다음을 반환하고 싶습니다.
baudet
elephant
왼쪽 결합 샘플을 기반으로 다양한 쿼리를 시도했지만 갇혀 있습니다.
var ct = from r in db.Resources
join lt in db.LocaleStrings
on r.ID equals lt.ResID into res
from x in res.DefaultIfEmpty()
select new
{
CultureID = x.CultureID,
LocaleText = x.LocaleText,
ResID = x.ResID
};
var text =
from c in db.Cultures
join t in ct
on c.ID equals t.CultureID into cults
from x in cults.DefaultIfEmpty()
select x;
해결책
더 나은 방법이 있다고 확신하지만 이것은 효과가있는 것 같습니다.
var ct =
from c in db.Cultures
from l in db.LocaleStrings
from r in db.Resources
where r.ID == l.ResID
select new
{
CultureID = c.ID,
LocaleText = l.CultureID == c.ID ? l.LocaleText : r.Name,
ResID = r.ID,
LSID = l.CultureID == c.ID ? l.ID : 0
};
var text =
from t in ct
where t.LSID != 0 || (t.LSID == 0 && !((from ac2 in ct
where ac2.LSID > 0 && ac2.CultureID == t.CultureID
select ac2.ResID).Contains(t.ResID)))
select new
{
CultureID = t.CultureID,
LocaleText = t.LocaleText,
ResID = t.ResID
};
제휴하지 않습니다 StackOverflow