I have 4 tables as following
table 1 Location A
public class CustmLocationA {
public int Location1_ID { get; set; }
public string Location1 { get; set; }
public string Location1_Descrip { get; set; }
public bool IsActive { get; set; }
}
Table 2 location B
public class CustmLocationB{
pubblic int Location2_ID { get; set; }
public string Location2 { get; set; }
public string Location2_Descrip { get; set; }
public int Location1_ID { get; set; }
public bool IsActive { get; set; }
}
Table 3 Location C
public class CustmLocationC {
public int Location3_ID { get; set; }
public string Location3 { get; set; }
public string Location3_Descrip { get; set; }
public int Location2_ID { get; set; }
public bool IsActive { get; set; }
public string Location2 { get; set; }
[NotMapped]
public bool LocBIsActive { get; set; }
[NotMapped]
public int Location1_ID { get; set; }
[NotMapped]
public string Location1 { get; set; }
[NotMapped]
public bool LocAIsActive { get; set; }
[NotMapped]
public string LocAandB { get; set; }
}
Table 4
public class CustmContact
{
public int contactID { get; set; }
public int Location3_ID { get; set; }
public int UserID { get; set; }
public bool Notify { get; set; }
public bool Access { get; set; }
[NotMapped]
public string UserName { get; set; }
[NotMapped]
public string LocationAll { get; set; }
}
What I have tried:
I'm trying to select all location C with related tables information in location A and B after that I need to select the selected user locations in table Contact (4th table) after that I need to remove all selected user table from selected locations but I found that cannot be applied to operands of type int and list of <int> in this line (a.Location3_ID != (from z in db.contacts where z.UserID == UserID select z.Location3_ID))
//Get Un-selected location by user ID
public List GetSelectedLocByUID (int UserID = 0)
{
var data = (from LocC in db.locationsC
join LocB in db.locationsB on LocC.Location2_ID equals LocB.Location2_ID
join LocA in db.locationsA on LocB.Location1_ID equals LocA.Location1_ID
select new CustmLocationC
{
Location1_ID = LocA.Location1_ID,
Location1 = LocA.Location1,
LocAIsActive = LocA.IsActive,
Location2_ID = LocB.Location2_ID,
Location2 = LocB.Location2,
LocBIsActive = LocB.IsActive,
Location3_ID = LocC.Location3_ID,
Location3 = LocC.Location3,
Location3_Descrip = LocC.Location3_Descrip,
LocAandB = LocA.Location1 + "-" + LocB.Location2,
IsActive = LocC.IsActive
}).Where(a => a.LocAIsActive == true && a.LocBIsActive == true && a.IsActive == true
&& a.Location3_ID != (from z in db.contacts where z.UserID == UserID select z.Location3_ID)
).OrderBy(a => a.Location1).ToList();
return (data);
}