Take the following Interfaces
Code: Select all
public interface IEventBookEntry {
int EntryId { get;set;}
int EventBookId {get;set;}
bool Flagged {get;set;
IEntry Entry {get;set;}
}
Code: Select all
public Interface IEntry {
int EntryId {get;set;}
DateTime EntryTimestamp {get;set;}
ICollection<IEventBookEntry> EventBookEntries {get;set;}
}
This means that i can write queries in my BLL layer which can run against either entity model, great stuff!
Let's take the following Linq method query:
Code: Select all
var eventBookEntries = new EventBookRepository().GetList(eb => eb.EventBookId == 123 && eb.Entry.EntryTimestamp > DateTime.Now.AddDays(-3));
You would expect the sql generated behind the scenes for this to be something like this
Code: Select all
SELECT Extent1.EntryId, Extent1.EventBookId, Extent1.Flagged
FROM EventBookEntries Extent1
INNER JOIN Entries Extent2 ON Extent1.EntryId = Extent2.EntryId
WHERE Extent1.EventBookId = 123
AND Extent2.Timestamp > 22/01/2016
Code: Select all
SELECT Extent1.EntryId, Extent1.EventBookId, Extent1.Flagged
FROM EventBookEntries Extent1
WHERE Extent1.EventBookId = 123
Code: Select all
SELECT Extent1.EntryId, Extent1.EntryTimestamp
FROM Entries Extent1
WHERE Extent1.EntryId = :EntityKeyValue1
My Question is how do you implement interfaces on navigation properties in such a way as to ensure entity framework will use inner joins in queries rather than the behavior exhibited above?
Thanks
Wayward