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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:25:24+00:00 2026-06-16T05:25:24+00:00

I coded an entity helper class and normally I use someting like that private

  • 0

I coded an entity helper class and normally I use someting like that

  private CVSystemEntities db;

public EntityHelper()
    {

        db = new CVSystemEntities();
   }

   public IQueryable<Members> GetMembersForRole(Role role)
    {
        if (!RoleExists(role))
            throw new ArgumentException(MissingRole);

        return db.Members.Where(m => m.RoleID == role.Id).OrderBy(m=>m.Name).AsQueryable();
    }

its Okay but If I use something like that

  private CVSystemEntities db;
  private IQueryable<Members> membersDb;


public EntityHelper()
    {

        db = new CVSystemEntities();
        membersDb = db.Members.Select(s => s);
   }

   public IQueryable<Members> GetMembersForRole(Role role)
    {
        if (!RoleExists(role))
            throw new ArgumentException(MissingRole);

        return membersDb.Where(m => m.RoleID == role.Id).OrderBy(m=>m.Name).AsQueryable();
    }

I’ve used membersClass instead of db.members. I created an instead from db.members.

So, What do you think about this way? Should I use somekind of this?
If you ask why you want to use it, I think that I don’t query my db so much,maybe is better?

  • 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-16T05:25:25+00:00Added an answer on June 16, 2026 at 5:25 am

    Should I use somekind of this? If you ask why you want to use it, I think that I don’t query my db so much, maybe is better?

    No, you’re doing exactly the same amount of work on the database. This:

    membersDb = db.Members.Select(s => s);
    

    … doesn’t execute a query on the database and then retain the results, as I believe you expect it will. Instead, it effectively builds a query – but retains the query for later.

    If you changed it to:

    IEnumerable<Members> membersDb;
    ...
    membersDb = db.Members.ToList();
    

    then that would just hit up the database once – but of course then you’d get stale data if the database changed. Maybe that’s okay – it’s unclear what the lifetime of your EntityHelper is – but it seems unlikely to me. Note that the call to ToList would also fetch all the members from the database – whereas otherwise your queries will have appropriate Where clauses, restricting what’s fetched. You probably don’t want to fetch the whole table into memory, unless it’s really small.

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

Sidebar

Related Questions

Consider the following code: @Entity @Table(name = a) public class A implements Serializable {
I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I have an Entity in Code First Entity framework that currently looks like this:
My code looks like: Entity e = new Entity(); e.name = ...; e.blah =
Imagine the following two entities. Element is simple class containing some data: @Entity public
I have an IQueryable whose Entity Framework 4 objects I would like to project
Here is my code @Entity class Parent extends Person { @OneToMany(cascade = CascadeType.ALL, fetch
I use Entity Framework code-first. DataBaseName - I want to create a database in
I am Using C# 2010 Entity framework code first If I have A class
I'm new to Entity Framework and am expanding an existing codebase. I'm using jQuery

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.