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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:01:24+00:00 2026-05-10T18:01:24+00:00

So like most new .NET developers you start of passing DataSets everywhere and although

  • 0

So like most new .NET developers you start of passing DataSets everywhere and although things do the job it doesn’t seem right.

The next progression is usually to create entity objects that extend a DAL base class so you have i.e.

public class User : UserDAL {     //User specific methods } public class UserDAL {   //Bunch of user specific properties   public User Load(int Id)   {     //Some low level ADO calls   }   private User LoadFromDataSet(DataSet ds)   {      //Load entity properties from DataSet    }     } 

User extends UserDAL objects that has low level data access calls using ADO.NET.

From here you go on to learn that this implementation means your tied to a data access layer and you make use of a separate entity, data access object and DAO interface for mocking or to easily swap out the DAO if need be. i.e.

public UserDAO : IUserDAO {   //Data access Functions } 

With use of generics and reflection or a good ORM you can relieve some of the more common data access CRUD operations i.e.

Public UserDAO<User> : BaseDAO<User>, IUserDAO {   //BaseDAO deals with basic crud so more custom data access methods can go here  } 

So basically that’s where I am currently at, aside from some other nice practices like using IoC to resolve the specific IUserDAO I want. But while I see the advantage to this structure I am also left feeling like I miss the old User.Load(1) method calls.

What I was wondering is would it be such a bad thing to inject my IUserDAO into the User entity and have that take care of the basic CRUD operations?

My understanding is that as a POCO the User entity would have no problems been passed over the wire and adding methods like Save(), Load() etc would have no relavence in the sense of a data transfer object.

But with that said my entities usually have lazy loaded collections which mean nothing in a DTO sense. Also, with WFP I believe can pick and chose which properties I want serializing, or at very least I could create a new UserDTO when I need to send it across the wire.

So basically, aside from that issue what are the other problems with making my User entity include DataAccess related methods? Also could someone clarify whether what I am talking about is referred to as an active record pattern or is this something else?

EDIT:

cristianlibardo noted:

As for potential drawbacks there is greater coupling to peristence code, resitence when following/updating associations, testability and querying.

There would be a greater some level of coupling but what I was thinking was somehting like the following:

public class User {    IUserDAO userDAO;    public User()    {          userDAO = IoCContainer.Resolve<IUserDAO>;    }   public User(IUserDAO userDAO)    {          this.userDAO = userDAO;    }    //DAL methods } 

So the coupling should be minimal and as for testability, I don’t see it as a problem as I can just inject a mock DAO into the entity.

Thanks to Brian Hasden, these are really good resources, but I guess I just wanted justification for something I was obviously going to do. Thanks for giving the said justification.

  • 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. 2026-05-10T18:01:24+00:00Added an answer on May 10, 2026 at 6:01 pm

    I came to the same conclusion. The load usually doesn’t make sense in the entity because once you have an instance, you’re either creating a new entity or you’ve already got a loaded entity. I’ve been using entities with Save (create and update) and Delete for years now without any issues. That being said, it’s usually useful to still have a DAO to do other things, so you’re not exactly combining the DAO and the entity. Most of the time for my entities the Save and Delete methods are just calling into the DAO Save and Delete methods.

    BTW, I usually combine a dirty flag with the entity to know when properties have been changed so that you don’t make unnecessary calls to save when the entity hasn’t changed.

    Typically, entities that don’t really do anything but contain getters and setters for private members mean you’re working with an anemic domain model. It’s an anti-pattern that’s fairly controversial.

    You can find more information about it at:

    http://www.martinfowler.com/bliki/AnemicDomainModel.html http://wrschneider.blogspot.com/2005/01/avoiding-anemic-domain-models-with.html http://www.dotnetjunkies.com/WebLog/richardslade/archive/2007/03/07/209401.aspx

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

Sidebar

Related Questions

Like most .NET developers I was watching the keynote for the Build Event in
Like most developers, I'm a business developer, which in essence consists of slapping a
Like most developers here and in the entire world, I have been developing software
Like most web developers these days, I'm thoroughly enjoying the benefits of solid MVC
Like most *nix people, I tend to play with my tools and get them
Like most people, I learnt C++ after C. I learnt C++ because it was
It seems like most examples of JPA/Hibernate entity bean classes I've seen do no
It appear that SQL Server like most other products Random Function really is not
I have a particular web application that like most others, has to account for
It seems like in most mainstream programming languages, returning multiple values from a function

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.