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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:03:17+00:00 2026-06-12T00:03:17+00:00

How can I add extension methods off the DbContext? This throws a stack overflow

  • 0

How can I add extension methods off the DbContext?

This throws a stack overflow exception:

    public IQueryable<T> All<T>() where T : class, new()
    {
        return this.All<T>();
    }

I am calling this using the code:

var u = UnitOfWork.All<User>().ToList();

Unit of work is:

    protected DBContext UnitOfWork = new DBContext ();

This also throws:

return this.All<T>().AsQueryable();

My Class:

public class DBContext : DbContext, ISession
{

    public DBContext ()
        : this("name=myConnString")
    {

    }

    public SurventrixContext(string dbcontext)
        : base(dbcontext)
    {

    }

    #region mappings

    private void UserMappings(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<User>().ToTable("tUsers");

        modelBuilder.Entity<User>().Property(x => x.UserID).HasColumnName("fU_UserID")
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

        modelBuilder.Entity<User>().Property(x => x.FirstName).HasColumnName("fU_First_Name");
        modelBuilder.Entity<User>().Property(x => x.LastName).HasColumnName("fU_Last_Name");
        modelBuilder.Entity<User>().Property(x => x.Login).HasColumnName("fU_Login");
        modelBuilder.Entity<User>().Property(x => x.Password).HasColumnName("fU_Password");
        modelBuilder.Entity<User>().Property(x => x.Email).HasColumnName("fU_Email");
        modelBuilder.Entity<User>().Property(x => x.Tel).HasColumnName("fU_Tel");
        modelBuilder.Entity<User>().Property(x => x.CreateDate).HasColumnName("fU_CreateDate");
        modelBuilder.Entity<User>().Property(x => x.LastPasswordChangedDate).HasColumnName("fU_LastPasswordChangedDate");
        modelBuilder.Entity<User>().Property(x => x.PasswordKey).HasColumnName("fU_PasswordKey");
        modelBuilder.Entity<User>().Property(x => x.KeyExpiryDate).HasColumnName("fU_KeyExpiryDate");
        modelBuilder.Entity<User>().Property(x => x.ApiToken).HasColumnName("fU_ApiToken");

        modelBuilder.Entity<User>().HasKey(t => t.UserID)
            .Property(x => x.UserID);
    }

    #endregion

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        UserMappings(modelBuilder);

        base.OnModelCreating(modelBuilder);
    }

    public DbSet<User> User { get; set; }

    public DbSet<ReportCommit> ReportCommit { get; set; }

    public DbSet<Organization> Organization { get; set; }

    public void CommitChanges()
    {
        this.SaveChanges();
    }

    public void Delete<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new()
    {
        this.Delete<T>(expression);
    }

    public void Delete<T>(T item) where T : class, new()
    {
        this.Delete<T>(item);
    }

    public void DeleteAll<T>() where T : class, new()
    {
        this.DeleteAll<T>();
    }

    public T Single<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new()
    {
        return this.Single<T>(expression);
    }

    public IQueryable<T> All<T>() where T : class, new()
    {
        return this.All<T>().AsQueryable();
    }

    public void Add<T>(T item) where T : class, new()
    {
        this.Add<T>(item);
    }

    public void Add<T>(IEnumerable<T> items) where T : class, new()
    {
        foreach (var item in items)
        {
            this.Add<T>(item);
        }
    }

    public void Update<T>(T item) where T : class, new()
    {
        this.Update<T>(item);
    }
}
  • 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-12T00:03:18+00:00Added an answer on June 12, 2026 at 12:03 am

    That is not an extension method! You have just created a method which calls itself in recursion.

    Extension method looks like:

    public static IQueryable<T> All<T>(this IQueryable<T> query) where T : class, new()
    {
        return query.All();
    }
    

    Edit:

    I checked for your code and you are most probably not looking for extension methods at all. You are looking for:

    public IQuerybale<T> All<T>() where T : class, new() 
    {
        return this.Set<T>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With extension methods we can easily add methods to any type. Obviously this opens
Is there any way I can add a static extension method to a class.
Background this post explains how one can consume extension methods in Powershell http://community.bartdesmet.net/blogs/bart/archive/2007/09/06/extension-methods-in-windows-powershell.aspx Compare
In principle, can I create a class library to store my Extension methods for
Using extension methods for C#, how can include an AddNode method (see below) in
C# 3.0 Extension methods add extensions to the base Type making calling that method
I want to be able to write extension methods so that I can say:
I have noticed that all of the Linq extension methods Where , Any ,
I can add and remove the last line in my dynamic form and calculate
I can add a normal rightBarButton to my navigation without a problem but now

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.