Home > Blockchain >  Pipe and Filter pattern in a Repository pattern returns "does not contain a definition for X...
Pipe and Filter pattern in a Repository pattern returns "does not contain a definition for X...

Time:04-28

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?

CodePudding user response:

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.

  • Related