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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:35:14+00:00 2026-06-02T01:35:14+00:00

Im a new user in stackoverflow and this is my first question hope i

  • 0

Im a new user in stackoverflow and this is my first question hope i wont be breaking any rules :)…

In my MVC3 project with EF4 and UnitOfWork Pattern,

When adding a new entity i have to check freshly added entities and the ones already stored in the database and calculate a column in new entity.

The problem is if i get the values from database newly added entities will not taken into consideration.

I overcome the problem via saving the unitofwork after each entity insert. But this means saving the current state of the context every time that specific entity is inserted.

I would like to know if this will bring some performance issues in the future. if so is there any other way to solve the issue?

Here is the relative code about the issue (simplified)

Model :

public class Group
    {
        public Guid GroupId { get; set; }
        public int Code { get; set; }

    }

Controller :

        UserGroup Group1 = new Group()
        {
            UserGroupId = Guid.NewGuid(),
            Code = (int)Math.Pow(2, (unitOfWork.GroupRepository.Get().Count()));
        };
        unitOfWork.GroupRepository.Insert(Group1);


        UserGroup Group2 = new Group()
        {
            UserGroupId = Guid.NewGuid(),
            Code = (int)Math.Pow(2, (unitOfWork.GroupRepository.Get().Count()));
        };
        unitOfWork.GroupRepository.Insert(Group2);

Insert Method : (derived from generic repository not to send all the repository pattern)

    public virtual void Insert(Group grouptoadd)
    {
        UnitOfWork unitOfWork = new UnitOfWork(Context);
        dbSet.Add(grouptoadd);
        unitOfWork.Save();
    }

If i won’t save UnitOfWork inside the Insert Method of GroupRepository class, When the Code of Group2 is calculated it wont get the Group1 into consideration.

Saving the unitOfWork inside the insert Method doesnt seem right. Tried to get the values from Context

(int)Math.Pow(2, (Context.Groups.Count()));

this code always returns 1. I could see the Entities inside the Context in debug mode but Count returns 0.

In the end i need : (newly added entities + entities stored in the database).Count()

  • 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-02T01:35:16+00:00Added an answer on June 2, 2026 at 1:35 am

    You might want to use DbSet’s Local property. Refer the article Why can I not see the property Local when using Entity Framework? if you don’t use DbSets.

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

Sidebar

Related Questions

this is my first question in stackoverflow. I am trying to use PHPExcel to
Hi, I'm a Rails newbie and this is my first stackoverflow question. I'm currently
This is my first post to StackOverflow and I am also new to Xcode
I am a new user to git and I am starting a new project.
I was browsing StackOverflow when I encountered this question. Here the author mentions his/her
Another question on StackOverflow is asking how this is done, but the general question
This is a continuation from the previous stackoverflow jQuery question I asked, but I
This is the first time i'm asking a question here at stack overflow so
I am a new user in Git world. I used to use Subversion (using
I need add a new user group for mediawiki. The new group has more

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.