When using an EF ObjectContext I see two different extensions methods with the same signature as consecutive choices. It doesn’t makes sense to me that there would be some magic that caused one or the other to get called based on which one I picked, so what is actually going on?

I’m assuming that
Campaignsis an instance ofDbSet<Campaign>?DbSetinheritsDbQuery, which implementsIOrderedQueryable, the definition for which is:As you can see, both
IQueryable<T>andIEnumerable<T>are implemented, but the definition ofIQueryableshows that it extendsIEnumerable:public interface IQueryable : IEnumerableSo basically, the extension method is implemented for
IEnumerable, but it’s also available fromIQueryableas it extends the original interface. Intellisense is picking up both of these options because you could end up implicitly or explicitly casting the type to anIEnumerable.The method that will actually be run will depend on the type on which it’s called. For example, on your
Campaignsinstance ofDbSet<Campaign>the method will translate it (if you’re using MS SQL) into aSELECT TOP 1...query, but if you’re calling it onCampaigns.ToList(), which isIEnumerable, it’ll return the item at the zero index. The implementation of the extension methods are different for each type.Hope that makes sense 🙂