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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:16:18+00:00 2026-05-18T23:16:18+00:00

i try to write a kind of generic repository to add method. Everything is

  • 0

i try to write a kind of generic repository to add method.
Everything is ok to add but I have table which is related with two tables with FOREIGN KEY.But Not working because of foreign key

alt text

public class DomainRepository<TModel> : IDomainRepository<TModel> where TModel : class
{
    private ObjectContext _context;
    private IObjectSet&#60;TModel&#62; _objectSet;

    public DomainRepository(ObjectContext context)
    {
        _context = context;
        _objectSet = _context.CreateObjectSet&#60;TModel&#62;();
    }

    // do something...
    public TModel Add<TModel>(TModel entity) where TModel : IEntityWithKey
    {
        EntityKey key = _context.CreateEntityKey(entity.GetType().Name, entity);          
        _context.AddObject(key.EntitySetName, entity);
        _context.SaveChanges();
        return entity;
    }
    // do something...
}

Calling Repository:

// insert-update-delete
public partial class AddtoTables
{
    public table3 Add(int TaskId, int RefAircraftsId)
    {
        using (DomainRepository<table3> repTask = new DomainRepository<table3>(new TaskEntities()))
        {
           return repTask.Add&#60;table3&#62;(new table3() { TaskId = TaskId, TaskRefAircraftsID = RefAircraftsId  });
        }
    }
}

How to add a new value if this table includes foreign key relation?

alt text

  • 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-18T23:16:19+00:00Added an answer on May 18, 2026 at 11:16 pm

    Damn hard to be sure answer is going to be helpful cause I dont think I udnerstand your interface clearly but in order to add objects with foreign keys to generic repositary you will have to add support to add object with foreign keys. I think if you have something like params ForeignKey[] somewhere in signatures you will make a step towards having support objects with foreign keys. Probably advice is worthless, but I got a worthy advice.

    Read Patterns of Enterprise Application Architecture by Martin Fowler and it will answer all of your questions – in this I am sure.

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

Sidebar

Related Questions

i try to write a kind of repository for effective Add,Update, Delete etc. But
I try to write to a large file, but it seems like it does
I try to write :ab in Vim for faster coding but the question is
I try to write a site with CodeIgniter but I've a problem with PHP.
I'm try to write a spec for a named scope which is date dependent.
it's kind a simple question but i have the doubt see the code belows
I try to write KSH script for processing a file consisting of name-value pairs,
I try to write a simple client/server application (all application is a bluetooth service
I try to write a simple Markdown parser in JavaScript. Therefore I want to
I try to write a macro in clojure that sets up a namespace and

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.