简体   繁体   中英

Pipe and Filter pattern in a Repository pattern returns "does not contain a definition for X... requires a receiver of type IQueryable<Y>

I'm trying to implement a basic Pipe and Filter pattern and testing it out in LinqPad 5.

The class that contains the extension methods looks as follows:

public static class MyExtensions
{
    public static IQueryable<PortfolioSection> AreNotDeleted(this IQueryable<PortfolioSection> portfolioSections)
    {
        return portfolioSections.Where(portfolioSection => portfolioSection.IsDeleted == false);
    }
    
    public static int AddMe(this int number, int newNumber){
        return number + newNumber;
    }
}  

In the Main section of linqpad I do the following:

void Main()
{
    PortfolioSections.AreNotDeleted().Dump();
}  

I've also tried to add AsQueryable to confirm this is not the issue:

void Main()
{
    PortfolioSections.AsQueryable().AreNotDeleted().Dump();
}  

In both cases I get the exception:

CS1929 'DbSet' does not contain a definition for 'AreNotDeleted' and the best extension method overload 'MyExtensions.AreNotDeleted(IQueryable)' requires a receiver of type 'IQueryable'

I'm following this article to find out more about the Pipe and Filter pattern and originally tried this out in my c# project, but switched to LinqPad when I discovered that the results of my query did not change when I included the extension method AndAreNotDeleted. In my project though there are no exceptions, LinqPad on the other hand throws the exception above.

Any ideas where I went wrong?

My connection type in Linpad is based on my project's Persistence library containing the DbContext. I had originally copied in all my domain classes representing the data entities forgetting that I simply needed to hit F4 and add a using statement pointing to my library containing the domain classes. This seems to have resolved all my issues in Linqpad and I'm now able to implement the pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM