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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:09:42+00:00 2026-05-31T02:09:42+00:00

I am trying my hands on MVC 2, ADO.NET EF and POCO. I have

  • 0

I am trying my hands on MVC 2, ADO.NET EF and POCO. I have generated my entity classes in a separate library using POCO generator.These POCO entities are used as ViewPages (Not sure if that’s the right way to design or do I need separate ViewModels classes ?)

Now, if I take case of a simple scenario where I need to add an Employee object( which is related to a Department Master), what then should be the recommended way to transfer these objects between layers.

Layered structure of the application is somewhat like this :

enter image description here

I have thought of various alternatives:

I have a method in the Employee Controller which is named AddEmployee() which accepts the FormCollection as parameter. Within the form collection I get posted data such as Employee Name, Age , Salary etc and the ID of the Selected Department .

1.) One way is that I can create another DTO say EmployeeDepartment DTO which will be used to map values from FormCollection as is. I can then break them at manager layer and use them to create entity objects i.e Employee Object and refer department by query similar to this:

e.Department =  Department.where(i => i.deptId == empDepDto.dept_id).first()

I am not a big fan of this and feel that every time there is a relation involved I have to add a DTO and then map it to my entity class.

2.) Second is probably the worst, i.e passing each object as parameter and then couple them in manager layer.

3.) Use POCO as is, Create a Employee Object and Deparment Object at controller layer and pass the POCO object

public void AddEmployee(FormCollection formCollection)
{
    Department d = new Deparmtent; d.id = ""; //based on the dropdown value
    d.name="" //based on the dropdown selected text;

    Employee e = new Employee; e.Name. e. sal....

    e.Department = d;

    EmployeeManager.AddEmployee(e);
}

But at manager layer I think , I still need to recreate the reference to the Department using LINQ which again is repetitive and doesn’t seems to be a clean solution.

Are there better ways of handling this ? Looking for recommendations and best practices.

  • 1 1 Answer
  • 1 View
  • 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-31T02:09:43+00:00Added an answer on May 31, 2026 at 2:09 am

    Firstly, is there any reason you’re not using MVC version 3? There’s no major breaking changes, so may as well upgrade?

    Secondly is there a reason for using FormCollection rather than the strongly typed model-binding? Just change your views to use the strongly typed HTML helpers ( like <%: Html.TextBoxFor(m => m.Property) %>), or make sure the name attributes match the property names, and have your controller receive the type, and model binding will do the rest. There’s plenty of tutorials showing this, and articles explaining it. Model binding will work with a name/value collection, like that posted as a form, or against JSON data, or you can find/write custom model binders that work against whatever wacky serialisation protocol you want.

    One thing to watch though when passing the actual entity types that Entity Framework will store around, is that you have to be careful when updating existing objects, or with foreign key references to existing objects – all your objects must be attached to the right Entity Framework context. To achieve that you will often see the objects received by the controller having their properties copied to a freshly retrieved entity from a context, either manually or by an object mapper of some kind.

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

Sidebar

Related Questions

I am trying to get my hands on MVC. I am from ASP.Net background.
I am trying to create a multiline Textbox using ASP.NET MVC with the following
I am trying to make an ASP.NET MVC 3 app in which I have
I am trying my hands on WPF MVVM. I have written following code in
Lately I have been trying my hands on Eclipse IDE for java development. I
I have an ASP.NET MVC app with the following deployment requirements: The URL structure
I am using MVC to create forms that are generated at runtime. For validation,
I'm using Ninject in an MVC project and am trying to implement Domain Events
In our current Asp.net MVC application we have 2 menu systems one accross the
I'm trying my hands on JqGrid with PHP MVC structure. I do not want

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.