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

  • SEARCH
  • Home
  • 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 6905427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:10:55+00:00 2026-05-27T08:10:55+00:00

How can I filter the IsSoftDeleted items out of this DbSet? var type =

  • 0

How can I filter the IsSoftDeleted items out of this DbSet?

var type = GetTypeFromString("Whatever");
var whatevers = Set(type);

Method

public dynamic Set(Type type)
{
    var set = dbContext.Set(type);
    return set;
}

Model

public class Whatever : BaseEntity
{
    public virtual string Name { get; set; }
}
public class BaseEntity
{
   public virtual int Id { get; set; }
   public virtual bool? IsSoftDeleted { get; set; }
}

EDIT: forgot to show Whatever derives from BaseEntity

  • 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-27T08:10:56+00:00Added an answer on May 27, 2026 at 8:10 am

    Your Whatever class doesn’t have any IsSoftDeleted property, so there’s nothing to filter. I’m going to assume Whatever is derived from BaseEntity.

    The main problem is that IQueryable<T>.Where doesn’t actually exist: it’s an extension method, and extension methods don’t play nice with dynamic types. If the compiler can see a type implements IQueryable<T>, you can type var.Where(…) and have the compiler resolve it to System.Linq.Queryable.Where(var, …). Since the type is dynamic in your example, the compiler doesn’t know it implements IQueryable, and will report an error when you try to call Where.

    You can cast the DbSet to IQueryable<BaseEntity> (as long as Type has BaseEntity as a base class), and call any filter on that. Do you actually use the dynamic type feature? If not, you can also consider dropping your custom Set function, and using the default DbContext.Set function.

    var query = (from e in (IQueryable<BaseEntity>)dbContext.Set(type)
                 where e.IsSoftDeleted != true
                 select e);
    

    Note: this is not the same as using dbContext.Set(type).Cast<BaseEntity>(): that won’t work, because a DbSet<BaseEntity> and a DbSet<Whatever> are incompatible. It is only with IQueryable and other interfaces with “out” type arguments that you can do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a cgridview that can filter data from relations table. This
I have a set of data with over 1000 entries. I can filter these
Can log4net filter and replace matched log message? <filter type=log4net.Filter.StringMatchFilter> <param name=AcceptOnMatch value=false />
I want to know how I can filter hotspots that are secured or public
Just want to know how I can filter out a result using mysql if
Is there any way i can filter out lines containing a certain word that
My project idea is to create filters so that I can filter out what
I am trying to figure out how I can filter out key and value
Magento 1.3 I'm trying to filter out of stock items from the productCollection. Using:
I have this: pm.php?v=unread Now in unread, you can filter too by pressing Messages

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.