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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:47:10+00:00 2026-06-11T18:47:10+00:00

My basic solution structure in every project is: Dal – Data access layer Business

  • 0

My basic solution structure in every project is:

  • Dal – Data access layer
  • Business logic which divided into two sections one is business entities and the second is business logic

So in my current practice my entities includes only data members and properties and NOT CRUD operations.
It’s always felt wrong to put CRUD operations within the Entity. My thought was..

  • It’s OK which entity deletes himself?
  • It’s OK which entity adds
    himself to the DB?

So i moved the CRUD operation to another library (Class) which represent my business Logic.

For example let say that we have an foo entity

public class Foo
{
    //Data Members
    private int _id;
    private string _Name;

    //Properties
    public int ID { get; set; }
    public string Name { get; set; }
}

So for this entity i will create a FooLogic library (Class) which holds all CRUD operations Like:

  • Add a New Entity
  • Delete an Entity
  • Get a list of entities
  • Update an entity
    And so on..

So what i am asking is:

  1. It’s right practice not to put the CRUD operations within the entity object?
  2. If so, What methods should i put in the entity himself of course beside “Print details”
  3. It’s Ok to have business Logic library (Class) for each important entity?
  • 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-11T18:47:11+00:00Added an answer on June 11, 2026 at 6:47 pm

    I can’t speak for what is absolutely correct in every circumstance (because nothing is, but also because I’m not a true “enterprise”-y developer), but…

    1. Database/entity operations, such as insertions and updates are usually handled by a Repository class that encapsulates every database operation. Repository methods accept or return an entity class object which represents a database record (or records, if you have a good ORM). An entity object should be a POCO and contain no logic that ties itself directly to the database – this allows you to swap out the default Repository implementation for a mock, which makes testing so much easier.
      • Note that in the .NET world, your EF DbContext is a repository already. You do not need to reimplement the Repository pattern yourself.
    2. Only accessors and mutators that operate on the entity object’s in-memory state. This includes trivial properties, but also things such as Person.GetFullName() which would concatenate the Person.FirstName and Person.LastName fields, for example.
      • So you would not have a method on your Person class called SendEmailTo() because that is not really an operation on the Person, but on your e-mail system.
    3. Generally speaking, no. Your business logic should happen in response to incoming messages (such as a client event, or a polling timer) and is a separate concern from mere repository tasks.

    Here’s how I’d implement a simple CRM (with a single entity, the Customer):

    An entity class DBCustomer:

    (presumably generated by Entity Framework) that represents a customer stored in the database.

    class DBCustomer {
        public String FirstName { get; set; }
        public String LastName  { get; set; }
        public String FullName  { get { return this.FirstName + " " + this.LastName; } }
    }
    

    A repository

    The Entity Framework DbContext is your repository object so no work needs to be done here.

    Business logic

    …such as a WCF message handler – but sometimes the logic is really simple, especially when the business action corresponds directly to a database action, e.g.

    StatusCode Customer_Add(CustomerXml newCustomerXml) {
        DBCustomer newCustomer = createNewCustomerFromXmlMessage( newCustomerXml );
    
        using( MyDbContext dbc = CreateDbContext() ) {
            dbc.Customers.Add( newCustomer );
            dbc.SaveChanges();
        }
    
        return StatusCode.Success;
    }
    

    Now you might notice that there seems to be a lot of useless layers here – I could use the CustomerXml class (which represents a deserialized formerly-XML-formatted message) and then call the EF context methods directly from the WCF message event handler, and it would would work for very trivial projects, however as projects grow you’ll see you need to add custom logic at every step, and suddenly things get unmanageable quickly.

    So for a simple data-driven website then a simple “do everything in the ame layer” approach would work fine, but an “entperprise” application with lots of niggles in the specification is going to need these extra layers.

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

Sidebar

Related Questions

This is a fairly basic question, which for some reason, a proper solution escapes
I'm looking for the most basic solution to create multiple indexes on a Java
I'm trying to decide how to implement a very basic licensing solution for some
Does anyone have a solution for a basic, compact Finite state machine/automata written in
This is a basic question but I am struggling to find a decent solution.
Basic question - is it possible to access the current Page from a static
This is the basic database structure for Users and UserRoles. My client wants to
I am using Visual Basic 6 I have the following code structure: FUNCNINFO is
Here's the basic structure of my menu. I cannot change that. <ul> <li><span>Bedroom</span></li> <li><span>Kitchen</span>
I'm looking at restructuring a large Maven project... A basic overview of our current

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.