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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:49:46+00:00 2026-05-24T23:49:46+00:00

I want to create a specific class to manage a collegion in my application.

  • 0

I want to create a specific class to manage a collegion in my application.

For example, I have a Store and I have a list of customers in a collection, in this collection I have a customer that is the customer of the month, and some customers that got a prize to get a discount for some reason. Let’s get to the code:

public class Store {
    public ICollection<Customer> Customers { get; set; }

    public Customer CustomerOfTheMonth 
    {
        //get and set for customer of the month
    }
    public ICollection<Customer> DiscountCustomers 
    {
        //get and set for customer of the month
    }
    public ICollection<Customer> GetAllCustomers 
    {
        //get and set for customer of the month
    }
}

But in my database, I only have two tables. Store, and Customer.

What I want to do is create a specific collection for the customer, to remove the logic from the Store and put in a specific class, after all, I don’t feel that the logic belongs to neither of those classes.

I wans tomething like this:

public class Store {
    internal CustomerCollection Customers { get; set; }

    //get and set for the propertis, just delegating for the collection
}        

public class CustomerCollection {
    public ICollection<Customer> Customers { get; set; }

    public ICollection<Customer> DiscountCustomers 
    {
        //get and set for customer of the month
    }

    //get and set with logic to filter the collection
}

Is there away to create this mapping and keep with only two tables in the database? I want to make it transparent to the application. Sorry for the code problems, typed in stack overflow and didn’t check the syntax.

  • 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-24T23:49:46+00:00Added an answer on May 24, 2026 at 11:49 pm

    don’t need to create your business logic to your model classes. Separate your logic to upper level. Here are your model classes. It will create your relationships as you want

    public class Store {
            public vertual ICollection<Customer> Customers { get; set; }
    
            //get and set for other propertis
        } 
    
    
    
    public class Customer{
    
        //get and set for other propertis
    }
    

    Create a repository or service layer to apply specific business logic ,

     public ICollection<Customer> GetDiscountCustomers() 
        {
           return dbContext.Customers.where(c=>c.discount=true).ToList()
        }
    

    if you want to load stores with customers at once you can use eager loading,

    public ICollection<Store> GetAllStores() 
            {
               return dbContext.Stores.Include("Customers").ToList()
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a bunch of errors. each specific to its own class
I want to create date with specific format for e.g 03-20-2010 have a format
I have a question... I want to create a class called thumb w/ all
i want to generate the Create Table Script for a specific entity Class. I
I want to create an object that acts as a specific class, such as
I want to create a batch while which finds specific lines in a batch
I want to create an installer EXE with some specific properties: it should be
I have a quite specific problem. I created a webapp and want to have
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass

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.