Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:05:20+00:00 2026-05-28T05:05:20+00:00

I currently use a generic repository pattern with Entity Framework code first: public interface

  • 0

I currently use a generic repository pattern with Entity Framework code first:

public interface IRepository<TEntity> where TEntity : class
{
    void Add(TEntity entity);
    void Delete(TEntity entity);
    TEntity GetById(int id);
    IEnumerable<TEntity> GetAll();
}

public interface IUserRepository : IRepository<User>
{
    IEnumerable<User> GetAllWithSubQuery();
}

public interface IBlackListRepository : IRepository<BlackList>
{
}

public interface IUserProccessedRepository : IRepository<UserProcessed>
{
}

public IEnumerable<User> GetAllWithSubQuery()
{
    var result = Database.Set<User>().Where(x => x.UsersProccessed.Any())
                                     .ToList();

    return result;
}

The model is setup as follows:

modelBuilder.Entity<UserProcessed>().HasRequired(x => x.User)
                                    .WithMany(x => x.UsersProccessed)
                                    .Map(x => x.MapKey("UserId"));

The problem is that I want to add a sub query into the LINQ above so it would do something similar to this:

SELECT      u.Email
FROM        Users u INNER JOIN UsersProcessed up ON u.Id = up.UserId
WHERE       u.Email NOT IN
            (
                SELECT  Email
                FROM    BlackList
            )

But since the User repository is User specific and there is no relationship setup between the User and BlackList in the model, I don’t know how to sub query BlackList. I don’t believe there should be a relationship between the User and BlackList tables because emails in BlackList are populated from a third party and are independent of the User table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:05:20+00:00Added an answer on May 28, 2026 at 5:05 am

    Perhaps I misunderstood, but you can define a sub query in LINQ like this:

    IQueryable<string> blacklistedMailAddresses =
        Database.Set<Blacklist>().Select(b => b.Email);
    
    var result = Database.Set<User>()
        .Where(x => x.UsersProccessed.Any())
        .Where(x => !blacklistedMailAddresses.Contains(x.Email))
        .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The application i am currently working on makes heavy use of the repository pattern
Currently in my application and using the unit of work pattern and generic repository,
What i currently use public static void MapObjectPropertyValues(object e1, object e2) { foreach (var
Following on from the excellent answer to my previous question: Linq Entity Framework generic
Within my code a have the following abstract superclass public abstract class AbstractClass<Type extends
I'm currently writing some code for UnconstrainedMelody which has generic methods to do with
I have an interface ( IRepository<T> ) that is currently being extended for each
Previously I was not using an interface for my generic repository. When I extracted
Previously I was not using an interface for my generic repository. When I extracted
I currently use the following base collection. abstract class BaseCollection : Collection<BaseRecord> { }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.