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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:19:11+00:00 2026-05-16T15:19:11+00:00

I am developing an piece of software where I have a few entities such

  • 0

I am developing an piece of software where I have a few entities such as:

public class Workspace
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public virtual List<Playground> Playground { get; set; }
        public virtual List<Workspace> Children { get; set; }
        public virtual List<Member> Members { get; set; }

        public virtual Workspace Parent { get; set; }
    }   

public class Playground
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public virtual List<Service> Services { get; set; }

        public virtual Workspace Workspace { get; set; }
    }

public class Service
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public virtual Playground Playground { get; set; }
    }

These are my EF4 POCO objects. I am using the repository pattern and the following interface:

public interface IRepository<T>
{
    void Add(T entity);
    void Delete(T entity);
    IEnumerable<T> Get(Expression<Func<T, bool>> expression);
    IEnumerable<T> Get();
    void Attach(T entity);

    int Save();
}

The repositories have an internal ObjectContext. I have a UnitOfWork that contains instances of my repositories and is responsible to save the changes made to them.

Am i doing it right so far?

I am implementing a Business Logic Layer like this:

public class DomainWorkspaceService : DomainServiceBase
    {

        public DomainWorkspaceService(Workspace workspace)
            : base(UnitOfWorkFactory.GetInstance())
        {
        }

        public void Create(Workspace workspace)
        {
            UoW.GetRepository<Workspace>().Add(workspace);
        }

        public void Delete(Workspace workspace)
        {
            var pservice = new DomainPlaygroundService();
            foreach (var playground in workspace.Playground)
                pservice.Delete(playground);

            foreach (var child in workspace.Children)
                Delete(child);
        }

    }

Now i’m not sure i am going in the right direction. My POCOs are (will be) responsible for validation and will enable me to do something like

SomeWorkspace.Children.Add(new Workspace {...});

Since these objects are associated with a context, when i save them will the changes to the collections also be saved in the database?

Also, I want that my Playgrounds can’t be created without a Workspace and Services without a Playground. Where should i create and delete them?

Thanks.

  • 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-16T15:19:12+00:00Added an answer on May 16, 2026 at 3:19 pm

    So far, so good.

    You probably want to move your Save method off of the Repository and onto the unit of work. In the Entity Framework, you have to save all changes in the context at once; you cannot do it per-type. Putting it on the Repository implies that only changes to the repository will be saved, which is probably not correct.

    You might want to implement the cascade from workspace to playground as database cascades (which the Entity Framework will recognize and support) instead of manually coding them.

    Yes, saving changes to the context will save all tracked changes, including related objects.

    Regarding adding, if you don’t expose the ObjectContext, then the only way that anyone will be able to add a Playground is via relationships with the objects you do expose.

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

Sidebar

Related Questions

I have been extremely naughty. I have been developing a piece of software (I'm
I'm currently developing a large piece of software base on JavaEE. We have followed
i have another piece for more advanced guys than me ;) I am developing
A few months back I put together a simple proof-of-concept piece of software for
I'm developing a piece of software, which reads data sent through the COM port
I am developing a piano in C#. I have the following piece of code
I'm developing an Office 2007 add-in. I would like to have a piece of
I'm developing a program that sends tweets. I have this piece of code: StringBuilder
I am developing a piece of software that records video from a live source
I'm developing a piece of software in C# and the end result is an

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.