convert below linq into sql from a in sysDB.PpBtcsptdKienNghiTienVayTsdbs join b in…
- User
convert below linq into sql from a in _sysDB.PpBtcsptdKienNghiTienVayTsdbs join b in _sysDB.DnTsbdHists on new { a.MaTaiSan, a.IdTtHist } equals new { MaTaiSan = b.MaTaiSan.Value, IdTtHist = b.MaHopDong } join c in _sysDB.Classification on new { NhomTs = b.NhomTs.HasValue ? b.NhomTs.Value.ToString() : string.Empty, ClassificationSchemeId = (int?)541, GroupClassificationCode = "TSBD" } equals new { NhomTs = c.ClassificationCode, c.ClassificationSchemeId, c.GroupClassificationCode } join d in _sysDB.TaiSanDs on a.MaTaiSan equals d.Mataisan into result1 from r1 in result1.DefaultIfEmpty() join e in _sysDB.TaiSanDsLoaiDongSans on r1.MaLoaiDongSan equals e.Maloaidongsan into result2 from r2 in result2.DefaultIfEmpty() join f in _sysDB.Classification on new { NhomTs = b.LoaiQhcsh, ClassificationSchemeId = (int?)215 } equals new { NhomTs = f.ClassificationCode, f.ClassificationSchemeId } into result3 from r3 in result3.DefaultIfEmpty() join g in _sysDB.Classification on new { NhomTs = b.PhongToaTtk, ClassificationSchemeId = (int?)543, GroupClassificationCode = "399TTKPTOA" } equals new { NhomTs = g.ClassificationCode, g.ClassificationSchemeId, g.GroupClassificationCode } into result4 from r4 in result4.DefaultIfEmpty() join h in _sysDB.TaiSans on a.MaTaiSan equals h.Mataisan join i in _sysDB.Classification on new { a1 = h.LoaiDatO, a2 = (int?)112} equals new { a1 = i.ClassificationCode, a2 = i.ClassificationSchemeId } into result6 from r6 in result6.DefaultIfEmpty() where a.IdTtHist == req.profileId && a.IdKienNghiTienVay == req.loanId select new CollateralGroupRes { CollateralGroup = b.NhomTs, CollateralId = a.MaTaiSan, CollateralName = b.TenTaiSan, CollateralGroupDesc = c.ClassificationName, AssetType = string.IsNullOrEmpty(r1.MaLoaiDongSan) ? r6.ClassificationCode : r1.MaLoaiDongSan, AssetTypeDesc = string.IsNullOrEmpty(r2.Diengiai) ? r6.ClassificationDescription : r2.Diengiai, Relation = r3.ClassificationCode == null ? null : r3.ClassificationCode.Trim(), RelationDesc = r3.ClassificationDescription, CollateralValue = b.GiaTri, BlockStatusCode = b.PhongToaTtk, BlockStatusDesc = r4.ClassificationDescription, }
- Assistant
Here's the equivalent SQL query for the given LINQ:
sql