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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:16:31+00:00 2026-05-12T10:16:31+00:00

I am trying to figure out how to tackle this problem. I have to

  • 0

I am trying to figure out how to tackle this problem. I have to insert some data into 2 tables lets call them Table A and Table B.

Table A has these columns
AId<PK>
A1 
A2
A3

Table B has
AId<PK>
A1
B2
B3
B4

Now my first question was should another repository call another repository? I don’t think this will solve my current problem but I just want to know this for future reference?

Now onto my problem.

when I call a create in my repository layer(TableARepository) to Create Table A. I create right away the fields for tableB too.

// linq to sql.
    TableA myATable = new TableA();
    dbContext.myATable.A1 = "hi";  // all these values would come from parameters.
    dbContext.myATable.A2 = "bye";
    dbContext.myATable.A3 = "go";

    dbContext.myATable.insertOnSubmit(TableA);
    dbContext.SubmitChanges();

    TableB myBTable = new TableB();
    dbContext.myBTable.AId = myATable.AId;
    dbContext.myBTable.A1 = myATable.A1;
    dbContext.myBTable.B2 = "2";
    dbContext.myBTable.B3 = "3";
    dbContext.myBTable.B4 = "4";

    dbContext.myATable.insertOnSubmit(TableB);
    dbContext.SubmitChanges();

So I think this is fine and I don’t think I would need to call myBTable repository(to create tableB) for this or a service layer.

Now here is the problem. TableB table should only have the information inserted into this table if and only if it is not equal to “hi”.

so param1 != "hi"  // insert 
   param1 == "hi"  // ignore and only insert table A

so this would mean I would have to wrap my TableB like this

if(param1 != "hi")
{
   TableB myBTable = new TableB();
    dbContext.myBTable.AId = myATable.AId;
    dbContext.myBTable.A1 = myATable.A1;
    dbContext.myBTable.B2 = "2";
    dbContext.myBTable.B3 = "3";
    dbContext.myBTable.B4 = "4";

    dbContext.myATable.insertOnSubmit(TableB);
    dbContext.SubmitChanges();
}

Now I am not sure if I should be doing this here since this seems almost like business logic. yet at the same time I am not sure how to do this business logic since either way I still have to pass in the value to insert into the create method even if it is null(A1 is a nullable field).

So should I call the tableB service layer pass in the TableA.Id, A1 and check what A1 is. If good then go to the TableB repository and insert it that way?

So TableARepostiory -> TableB service layer -> TableBRepository(if found that that value != “hi”).

So I am not sure what to do.

  • 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-12T10:16:31+00:00Added an answer on May 12, 2026 at 10:16 am

    No – i cannot think of a reason for a repository to call another repository, nor another service. Their only concern should be persisting your entities and retrieving entities from a datastore. They should be ignorant to most aspects of your application except for the underlying domain.

    It sounds like you are assuming their should be a repository per table, which is incorrect. There should be a repository per aggregate root, and that repository should take care of storing data to all of the underlying, related tables. It is OK for the repository to have some logic pertaining to where or how to save the data, but it would be best for that to be encapsulated in a common area when possible.

    For example if you were to have person objects and needed to save to different tables according to gender, you could do this using inheritance ( if (person is Woman) save here… ) or properties on the object ( if (person.Gender == Gender.Female) save here… ) or Specifications ( if (FemaleSpecification.IsSatisfiedBy(person)) save here… ).

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

Sidebar

Related Questions

trying to figure out why this is happening - I have an input text
Trying to figure out a way to throw out attributes in this data that
I have a problem and Google hasn't helped me much. I'm trying figure out
I've been trying to figure this out for a couple days now. I have
I have got myself into a bit of a mess trying figure out the
Trying to figure out how to hook into some web part verb events; specifically,
I'm trying to figure out what the best way to tackle this would be.
Trying to figure out how I can do this properly. The print_r looks like
I'm trying to wrap my head around this and figure out what would be
Trying to figure out what I'm doing wrong when trying to put $(this) in

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.