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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:56:41+00:00 2026-06-02T03:56:41+00:00

I am working on a simple WCF application and I am having trouble with

  • 0

I am working on a simple WCF application and I am having trouble with properly setting up the Repository pattern. The communication pattern of the application is roughly as shown here.

I am concerned with the part that says Admin Console Mode. In this mode, the admin has access to some admin features like adding users and viewing existing users etc.

Abstract contract of one of the entities, Users, needed for this mode, is as follows:

public interface IUserRepository
{
    byte AddUser(string _loginname, string _loginpass);
    Users ShowAllUsers();
}

The concrete implementation of this repository:

public class UserRepository : IUserRepository
{
    public UserRepository(string connectionString)
    {
        _connectionString = connectionString;
    }

    public byte AddUser(string _loginname, string _loginpass)
    {
        . . .
    }

    public Users ShowAllUsers()
    {
        string query = "select login_name,created_time from users";

        using(SqlConnection conn = new SqlConnection(_connectionString))
        {
            using(SqlCommand cmd = new SqlCommand(query, conn))
            {                    
                conn.Open();

                using(var reader = cmd.ExecuteReader())
                {
                    if(!reader.Read())
                        return null;

                    return new Users
                    {
                        Login_Name = reader.GetString(reader.GetOrdinal("login_name")),
                        Login_Pass = reader.GetString(reader.GetOrdinal("login_pass")),
                        Created_Time = reader.GetDateTime(reader.GetOrdinal("created_time")),
                    };
                }
            }
        }
    }
}

From the Host layer, How do I access the list of Users objects returned from the ShowAllUsers method? I tried this way:

public void ShowUsers()
{
    Users user = _repo.ShowAllUsers();

    Console.WriteLine("Name\tCreated Time");

    foreach(Users u in user)
    {
        Console.WriteLine("{0}\t{1}",u.Login_Name,u.Created_Time);
    }
}

From what I understand, this does not work obviously since the Users object is not an enumerable object. How do I modify the Users entity and the repository contract and the repository implementation so that the Users object is returned to be displayed on the screen?

Users.cs
UserRepository.cs
IUserRepository.cs

  • 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-02T03:56:42+00:00Added an answer on June 2, 2026 at 3:56 am

    Entity:

    // note the singular form, it makes much more sense for me, as far as the object represents a single entity (user)
    // also not an interface, optionally
    public class User : IUser
    {
    }
    

    Repository:

    public class UserRepository : IUserRepository
    {
        public IEnumerable<IUser> ShowAllUsers()
        {
            ...
            while (reader.Read())
            {
                 yield return new User
                 {
                     ...
                 };
            }
        }
    }
    

    I recommend yo use interfaces everywhere, because if you will want to switch from ADO.NET query to an ORM, you will need to rewrite much less code.


    Usage:

    foreach (User u in users)
    {
        Console.WriteLine("{0} created on {1}", u.Login, u.CreationTime);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple WCF service, MiniCalcService which has only one operation
I created a simple WCF application which expose one operation. This operation takes a
I'm working on some WCF Rest services, following some tutorials to make some simple
Simple issue. I'm working on a proof-of-concept for an application with additional database connection,
I have developed one WCF application, and it is working as a middle layer
I am working on a WCF Workflow Service Application, and I simply have a
I'm working on an application in WCF and want to receive events in the
Suppose this simple scenario: My client has an already working .net application and he/she
I'm working on adding a WCF services layer to my existing .NET application. This
I have developed a silverlight application with WCF-RIA services and is working fine. I

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.