The following are some stuffs behind the scene.
public class User : BaseTransactionModel
{
public Guid UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Transaction
{
public int TransactionId { get; set; }
public string TransactionName { get; set; }
public int TransactionHistoryId { get; set; }
public virtual TransactionHistory TransactionHistory { get; set; }
}
public class TransactionHistory
{
public int TransactionHistoryId { get; set; }
public DateTime CreatedDateTime { get; set; }
public Guid UserId { get; set; }
public int TransactionId { get; set; }
public virtual ICollection<User> Users { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
}
public class BaseTransactionModel
{
public int TransactionHistoryId { get; set; }
public int TransactionId { get; set; }
public virtual TransactionHistory TransactionHistory { get; set; }
public virtual Transaction Transaction { get; set; }
}
With the above entities, I am trying to get all the Transactions from a User on a specified Date.
So I tried including both User and TransactionHistory on the Transaction DbSet:
Context.Transaction
.Include(t => t.User)
.Include(t => t.TransactionHistory)
...
I wanted to add a where clause that filter the transaction from the date in transaction history entities:
Context.Transaction
.Include(t => t.User)
.Include(t => t.TransactionHistory)
.Where(t => t.TransactionHistory.CreatedDateTime <= StartDateFilter && t.TransactionHistory.CreatedDateTime >= EndDateFilter)
but could not able to do so. Since TransactionHistory is also a list of entity (or whatever it is called).
What could be the possible solution to get what I am trying to achieve ?
PS: I am new to EF and the title could be misleading. If so, feel free to update it.