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

The Archive Base Latest Questions

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

I have this test in my test base: public void WorksWithAreaUsers() { using (new

  • 0

I have this test in my test base:

public void WorksWithAreaUsers()
        {
            using (new TransactionScope())
            {
                //arrange
                var userBusiness = new UserBusiness();
                var user = new User
                {
                    Name = "TestUser###",
                    Login = "domain\test-user###"
                };
                userBusiness.Add(user);

                var areaBusiness = new AreaBusiness();
                var area = new Area
                {
                    Name = "TestArea###",
                    Description = "Test Area Description",
                    Users = new List<User> { user }
                };

                //act
                areaBusiness.Add(area);

                //assert
                var areaFromDb = areaBusiness.FindById(area.AreaID);
                Assert.IsNotNull(areaFromDb.Users);
                Assert.IsTrue(areaFromDb.Users.Count > 0);
                Assert.IsTrue(areaFromDb.Users.Any(c => c.UserID == user.UserID));
            }
        }

What it is doing:

  • Inserts a new user into the base;
  • Inserts a new area into the base, with the user relationship;

What actually happens:

  • The new user is inserted;
  • The new area is inserted;
  • The new user is inserted again, with area relationship;

What can be happening?

More information:

  • Area and User aren’t EntityObjects really. I am mapping DTO/Entity using AutoMapper, I think the problem is in this logic. In a certain moment, I have to map between the List and the EntityCollection. I create a new EntityCollection and put the User converted into a UserEntity in this collection, using the EntityCollection.Add method. I think I should use Attach in order to not create a new entity, but this method doesn’t work when called from an EntityCollection without the proper bindings.

Do you suggest anything clever than that, or any workaround to solve this issue? I really need the project layers (Web -> Business -> Data -> EF), asp.net working directly with EF is something we can’t do here, for modularity reasons.

EDIT:

I’m giving up the idea of using AutoMapper to do this job =/ I don’t have a lot of entities, and the changes I need to do in this library in order to work requires some effort, it isn’t something trivial to do. It is better to do the mapping by myself.

  • 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-12T08:46:49+00:00Added an answer on May 12, 2026 at 8:46 am

    I assume your User object has an Area property that can also be used to establish the relationship between the entities. Instead of setting Area.Users equal to a new list,
    after you create the area object just set User.Area equal to the new area. This is how I handle associating new entities and it works reliably.

    EDIT

    If I understand what you are doing, you are creating business objects (BOs) that later create entity objects (EO) and attach those EOs to a context and save them.

    Assuming I have the basics correct, determing the exact cause of you problem requires seeing the code for how the respective BOs create EOs and attach them to the context.

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

Sidebar

Ask A Question

Stats

  • Questions 145k
  • Answers 145k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use a VBScript file to replace wget for… May 12, 2026 at 8:47 am
  • Editorial Team
    Editorial Team added an answer Personally, when I build a plugin, I try to make… May 12, 2026 at 8:47 am
  • Editorial Team
    Editorial Team added an answer Stubbing really is the way to go here. In my… May 12, 2026 at 8:47 am

Related Questions

I'm testing the delete method of an abstract base repository class which is inherited
So I was playing around a little more with attributes in .NET, and realized
I have the code below : public class Anything { public int Data {
Maybe I am wrong, but this seems to be a very basic question. Suddenly
I have a reference application that I use to work through DDD issues, and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.