I have two tables
Contracts
Id | StartDate | EndDate
ExcludedContracts
Id | ContractId
I am using the following statements to get both sets of data:
var excludedContracts = from Excluded in
DataContext.ExcludedTransportContracts
select Excluded;
// Get a collection of all live sites first
var liveContracts = from Contracts in DataContext.Contracts
where Contracts.EndDate > DateTime.Now
select Contracts;
I need to select all contracts that don’t have a record in the ExcludedContracts table. I’ve been battling with WHERE queries for a while but had no luck.
How do I do a query similar as I would an instatement IN(1,2,3) SQL?
Thanks!
Are the two tables not related at the data level? Ie a Contract object having a list of ExcludedTransportContracts as a property?
From the look of the data this is probably how they should be related, then you can do something like
var liveContract = DataContext.Contracts.Where(c => c.ExcludedTransportContracts.Count() == 0 && c.EndDate > DateTime.Now )Was off the top of my head so the code may need slight alterations.