I trying to join 3 tables and I need to compare two values to make the first relationship, and make the second relationship based on that.
But I don't know how to use the Join() method to do that.
I need to return value when PRTCL_BLQ and SQ_BLQ of TB_TABLE_1 is equals PRTCL_BLQ_VL and SQ_BLQ_VLR of TB_TABLE_2.
After that I need to compare the VARAJUIZO_BLQ_VLR of returns with VARAJUIZO of TB_TABLE_3 and than return the NM_VARAJUIZO and TRIBUNAL values.
I have these 3 tables:
First table:
namespace Infrastructure.Data.Model
{
using System;
using System.Collections.Generic;
public partial class TB_TABLE_1
{
public decimal Attr1 { get; set; }
public decimal Attr2 { get; set; }
public string Attr3 { get; set; }
public Nullable<decimal> Attr4 { get; set; }
public string PRTCL_BLQ { get; set; }
public string SQ_BLQ { get; set; }
}
}
Second table:
namespace Infrastructure.Data.Model
{
using System;
using System.Collections.Generic;
public partial class TB_TABLE_2
{
public decimal Attr1 { get; set; }
public decimal Attr2 { get; set; }
public string Attr3 { get; set; }
public Nullable<decimal> Attr4 { get; set; }
public string PRTCL_BLQ_VLR { get; set; }
public string SQ_BLQ_VLR { get; set; }
public string VARAJUIZO_BLQ_VLR { get; set; }
}
}
Third table:
namespace Infrastructure.Data.Model
{
using System;
using System.Collections.Generic;
public partial class TB_TABLE_3
{
public string VARAJUIZO { get; set; }
public string NM_VARAJUIZO { get; set; }
public string TRIBUNAL { get; set; }
}
}
Query
return db.TB_TABLE_1
.Join(TB_TABLE_2,
tb1_prtcl => tb1_prtcl.PRTCL_BLQ,
tb2_prtcl => tb2_prtcl.PRTCL_BLQ_VLR
{}) //I don't know how to compare the 2 values (PRTCL_BLQ and SQ_BLQ) and continue that to join the third_table =(
.Where(x => x.Attr1 == attr1 &&
x.Attr2 == attr2 &&
x.Attr3 == attr3)
.ToList()
.Select(x => new ReturnClass
{
Value1 = x.Attr1
Value2 = x.Attr2
Value3 = x.Attr3
Prtcl = x.PRTCL_BLQ
Sq = x.SQ_BLQ
}).ToList();
}