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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:03:01+00:00 2026-06-11T14:03:01+00:00

This question is like a Part 2 of my previous one here! Here are

  • 0

This question is like a Part 2 of my previous one here!

Here are things I learned and hoping to be true:

  1. Do not use Data Entity Context as Static
  2. Dispose the data context after used -usually after one time-
  3. Pass parameters into UPDATING Entity method instead of the Entity
    (which I’ll explain and in here my crossroad lies)

Here is my modified code:

public class ManagerBase
    {
        private NoxonEntities _entities = null;

        public NoxonEntities Entities
        {
            get
            {
                if (_entities == null)
                    _entities = new NoxonEntities();

                return _entities;
            }
        }
    }

//Managers uses ManagerBase class as a Base class
MemberManager currentMemberManager = new MemberManager();
currentMemberManager.Save(memberId, username, password, languageId);


//MemberManager class
public Member Save(long memId, string username, string password, int langId)
        {
            using (var Context =   base.Entities)
            {
                var Data = Context.Member.First(c => c.Id == memId);

                Data.Username = username;
                Data.Password = password;
                Data.Language = Context.Language.First(c => c.Id == langId); //Gets the foreign entity

                Context.SaveChanges();

                return Data;
            }
        }

This works without exception. But normally this SAVE method is an implemented method by an interface. So, I’d rather to pass an OBJECT value to the SAVE method than passing all the fields like above.
For example I’d like to use this:

//Member is an EntityFramework Object which was created during EF Model when I added by visual studio
//Filter is the method that returns an EntityFramework Object from EF (and eventually database) with given some arguments
//SomeArguments could be  MemberId = 2
Member modifiedMember = currentMemberManager.Filter(someArguments);
modifiedMember.UserName = "newvalue";
currentMemberManager.Save(modifiedMember);

In the SAVE method perhaps I could use like this:

public Member Save(Member modifiedMember)
            {
                using (var Context =   base.Entities)
                {
                    var Data = Context.Member.First(c => c.Id == modifiedMember.Id);

                    Data.Username = modifiedMember.Username;
                    Data.Password = modifiedMember.Password;
                    Data.Language = Context.Language.First(c => c.Id == modifiedMember.LanguageId); //Gets the foreign entity

                    Context.SaveChanges();

                    return Data;
                }
            }

If I am gonna use this just like the one right above, I think I should NOT use the passing object EF Object and instead perhaps I should use some other class that I’ll write just to map the parameters to the EF Member Entity.

First question: Is this a good approach?

public class MyMember
{
    public long Id { set; get; }
    public string Username { set; get; }
    public string Password { set; get; }
    public int LanguageId { set; get; }
}

MyMember.Username = "NewValue";
MyMember.LanguageId = 4; //4 as in new value
currentMemberManager.Save(MyMember); //As you can see MyMember is not an EF Entity in here

But this will take long time since there is already some written code.

Second question: Can’t I use an EF Entity object OUTSIDE and modify it there to save it IN the MemberManager class?

Again, thank you very much for your help in advance.

  • 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-11T14:03:02+00:00Added an answer on June 11, 2026 at 2:03 pm

    Here is the answer:

    How to update entity?

    And I thank you for the ones who helped me.

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

Sidebar

Related Questions

this question is like this one , except it's for PHP testing via browser.
My question like this: I have a JTable, I put a JProgressBar in one
Kind of like this question I have many text snippets that I use many,
This question is a follow-up question to my previous one that can be found
This may seem like a very basic question, since I'm not familiar with jQuery,
For the purposes of this question, I do not have the ability to use
following this question : Best approach for oldschool 2D zelda-like game Thank to previous
This is conjunction with my previous question https://stackoverflow.com/questions/8428911/jcs-disk-cache-data-retrieval Does JCS read from disk even
Ok guys, this question is related to my previous one. If I have set
I asked this question earlier and thought it was fixed, but it's not. Previous

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.