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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:00:26+00:00 2026-05-23T07:00:26+00:00

I have the following code structure. It is a WPF application with DAL exposed

  • 0

I have the following code structure. It is a WPF application with DAL exposed thru WCF services. we have created our domain entities and we are passing them after populating from EF entities.

EDMX Generated Code:-

public partial class EDiscDbConnection : ObjectContext
{
    #region Constructors

    /// <summary>
    /// Initializes a new EDiscDbConnection object using the connection string found in the 'EDiscDbConnection' section of the application configuration file.
    /// </summary>
    public EDiscDbConnection() : base("name=EDiscDbConnection", "EDiscDbConnection")
    {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }
}

Now for instantiating ObjectContext, we have created a BaseDAL and every DAL in the application inherits from BaseDal

BaseDAL:-

public class BaseDal
{
    public EDiscDbConnection context; // EF Content used for connection to the Database.

    /// <summary>
    /// Base constructor to initilize the Entity Framework Content.
    /// </summary>
    public BaseDal()
    {

        string connstring = ConfigurationManager.ConnectionStrings["EDiscDbConnection"].ConnectionString;
        //Decrypt Connection String
        context = new EDiscDbConnection(Encryption.GetDecryptedString(connstring, "F045FBC3A427A1018E297BF442216C3FB3D62F51B57A33AC744B6238E05ADB08"));
        //context = new EDiscDbConnection();

    }
}

DAL is as follows:-

public partial class PatientChartDal : BaseDal
{
  public List<UserFacility> GetAllFacilities()
    {
        List<UserFacility> userFacilities = new List<UserFacility>();

        IEnumerable<Facility> userFac = from fac in context.Facilities
                                        from usrfac in fac.UserFacilityMappings
                                        where fac.IsActive
                                        select fac;

        if (userFac != null && userFac.Count() > 0)
        {
            userFacilities = new List<Domain.UserFacility>();
            foreach (var u in userFac.Distinct())
            {
                userFacilities.Add(new Domain.UserFacility()
                {
                    Name = u.Name,
                    FacilityId = u.FacilityId,
                    //FacilityConfiguration = GetFacilityConfiguration(u.FacilityId),
                    //UserConfiguration = GetFacilityUserConfiguration(u.FacilityId, userId),
                    Code = u.Code,
                    //TxAreaID = u.TxAreaID,
                    TimeZone = ConvertToDomainEntity(u.Seed_TimeZone)
                }
                );
            }
        }

        return userFacilities;
    }
}

I have following questions regarding this implementation

  1. We are not disposing of EDiscDbConnection. Is this a memory leak ?
  2. Will implementing using() in GetAllFacilities() method automatically dispose EDiscDbConnection or i have to implement IDisposable in BaseDAL?
  3. I am very rarely getting an error “already an open DataReader associated with this Command which must be closed first “. Can this be associated with not disposing the EDiscDbConnection.

What is the best practices people are following in these cases. Please suggest.

  • 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-23T07:00:27+00:00Added an answer on May 23, 2026 at 7:00 am

    Referring to this question: Entity Framework and Connection Pooling

    In short, you should wrap your queries in a using() statement to ensure that they are garbage collected after each query execution.

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

Sidebar

Related Questions

I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I am using Visual Basic 6 I have the following code structure: FUNCNINFO is
I have following situation: I'm developing an address-application to store the details of our
I have the following structure in a Java Web Application: TheProject -- [Web Pages]
I have the following code with a structure array with data to make some
I have the following PHP code to display the file structure of my site.
I have the following code structure: <input type=checkbox name=some_name_1 value=some_val /> <input type=text name=input_name_1

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.