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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:35:40+00:00 2026-05-27T04:35:40+00:00

I am struggling with solving how to handle insertions and deletions with MVC3 and

  • 0

I am struggling with solving how to handle insertions and deletions with MVC3 and the Entity Framework 4.2

My Setup:
Website accesses my Service Layer, which uses the Repository Pattern to fetch and return my Model(POCO) objects. The Solution is separated into the following projects:

  DAL(Data)
  BAL(Service layer in here)
  MODELS (Poco objects)
  WEBSITE (presentation)

My Problem:
I need to be able to control the adding and deletion of objects and run whatever business logic I like. This should be done in the Service Layer.

Example of Problem: I have an Account class with an ICollection of AccountContact objects. Each AccountContact object has an ICollection of PhoneNumber objects. What I envision is a Service method something like this

  AddAcountContact(Account account, AccountContact accountContact){
     //Run business logic to ensure that this account contact can be added
     account.AccountContacts.Add(accountContact);
     unitOfWork.SaveChanges();

  }
  DeleteAccountContact(Account account, AccountContact accountContact){
     //Run business logic to ensure that this account contact can be deleted
     account.AccountContacts.Remove(accountContact);
     unitOfWork.SaveChanges();
  }

Unfortunately I have no way to force adding and removing through my Service class. A developer could easily insert/remove directly from the presentation layer. Anyone have any ideas or know common solutions to this problem? Perhaps I am doing something wrong….

  • 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-27T04:35:41+00:00Added an answer on May 27, 2026 at 4:35 am

    If you expose class with public collection property allowing Add and Remove you are telling developers that they can call those methods. You can define the coding policy and use code review to check that policy is followed but it is only workaround. Still anybody could forget about that and call Add or Remove directly because your classes are wrongly designed.

    The main problem here are entities exposed directly to UI. If you don’t want direct modification of entities in UI layer simply don’t expose them to that layer. Use another type (DTO / View model) with readonly collections exchanged between service layer and UI layer and convert that type to entity inside service layer. Another option is adding validation directly to entities or custom collection types.

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

Sidebar

Related Questions

Iam struggling with NHibernate and its lazyload. I have a structure which I simplified
Im struggling to create a functionality which keeps on incrementing css property of an
im struggling to connect to my mysql service running on my local windows 7
I've been struggling with this for a while. I'm solving the longest common subsequence
Struggling with the basics here. I want to setup an array, and fill it
I'm currently struggling with a problem I'd like you to help me solving... basically
I have an importer process which is running as a windows service (debug mode
Struggling here, I'm Using .draggable on a div which works fine but I also
Struggling to get any list function to work. I've been fine with _show and
Struggling with a bit of a mystery regarding a ghost like JESSIONID Cookie. I'm

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.