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 8813091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:45:29+00:00 2026-06-14T03:45:29+00:00

I am getting the error Non-static method requires a target. when I run the

  • 0

I am getting the error “Non-static method requires a target.” when I run the following query:

var allPartners = DbContext.User
                           .Include(u => u.Businesses)
                           .Where(u => u.Businesses.Any(x => x.Id == currentBusinessId))
                           .ToList();

My entites are defines like this:

public class User : Entity
{
    public virtual List<Business> Businesses { get; set; }
}

public class Business : Entity
{
    public virtual List<User> Users { get; set; }
}

public class Entity
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid Id { get; set; }
}

And my context is configured like this;

public class Context : DbContext, IDatabaseSession
{
    public DbSet<Business> Business { get; set; }
    public DbSet<User> User { get; set; }

    public Context()
        : base("DefaultConnection")
    {

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Conventions.Remove
            <System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();

        Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>());

        modelBuilder.Entity<User>()
            .HasMany(u => u.Businesses)
            .WithMany(b => b.Users);
    }
}

What have I done wrong?

  • 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-06-14T03:45:30+00:00Added an answer on June 14, 2026 at 3:45 am

    The problem boiled down to the query. My original question had this query:

    var allPartners = DbContext.User
                           .Include(u => u.Businesses)
                           .Where(u => u.Businesses.Any(x => x.Id == currentBusinessId))
                           .ToList();
    

    Which wasn’t quite accurate, I had in fact removed the error in an attempt to ask my question succinctly. The query was actually:

    var currentBusiness = GetBusiness();
    var allPartners = DbContext.User
                           .Include(u => u.Businesses)
                           .Where(u => u.Businesses.Any(x => x.Id == currentBusiness.Id))
                           .ToList();
    

    When the GetBusiness method returned null the error was thrown. Simply ensuring that I don’t pass a null object into the expression made the error stop.

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

Sidebar

Related Questions

I'm getting the Cannot make static reference to a non-static method error but I
I am getting an error An object reference is required for the non-static field,
Im getting the following error when trying to run hosted powershell scripts before upgrading
I'm getting exception An object reference is required for the non-static field, method, or
I'm getting an An object reference is required for the non-static field, method, or
I keep getting the following error in Eclipse: Type Cannot make a static reference
I am getting this error: An object reference is required for the non-static field,
I'm getting a compile error conversion from 'int*' to non-scalar type 'foo< int>' requested
I'm getting a Call to a member function fetchColumn() on a non-object error when
Now getting error Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT

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.