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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:21:58+00:00 2026-05-20T00:21:58+00:00

I have 3 Tables. Metadata, Rules, and a NxN relationship MetadataRules. I’m inserting a

  • 0

I have 3 Tables. Metadata, Rules, and a NxN relationship MetadataRules.

I’m inserting a Metadata, and my object contains a list of Rules that are retrieved from DB.

myMetadata.Rules = myListOfrules;

When i perform an insert, all the rules in myListOfRules are duplicated in the Rules table, instead of just creating a relationship.
I’m inserting it with:

public static void InserirTipoMetadata( TA_TIPO_METADATA tipoMetadata ) {
    using ( EnterpriseContext context = new EnterpriseContext() ) {
        context.TipoMetadata.AddObject(tipoMetadata);
        context.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);
    }
}

What should i do to not duplicate the Rules?

Thanks!

  • 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-20T00:21:58+00:00Added an answer on May 20, 2026 at 12:21 am

    I found a solution, but I don’t think it is the right one…

    public static void InserirTipoMetadata( TA_TIPO_METADATA tipoMetadata ) {
                using ( EnterpriseContext context = new EnterpriseContext() ) {
                    List<TA_REGRA_VALID> regras = new List<TA_REGRA_VALID>();
                    foreach ( var v in tipoMetadata.TA_REGRA_VALID ) {
                        regras.Add(context.Regra.Single(p => p.CO_SEQ_REGRA == v.CO_SEQ_REGRA));
                    }
                    tipoMetadata.TA_REGRA_VALID = regras;
                    context.TipoMetadata.AddObject(tipoMetadata);
                    context.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);
                }
            }
    

    I’m selecting the rules again from the DB before trying to add. Is that the correct way?

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

Sidebar

Related Questions

In my database I have tables that define types for example Table: Publication Types
When I have tables in my database that have PK/FK relationships (int) and when
Into I have two tables profile and name , the profile table contains some
Quick question that requires a long explanation.. Say I have two tables - one
I have an entity that, in addition to a few common properties, contains a
I have two tables in APEX that are linked by their primary key. One
I've got a bunch of strongly typed DataSet that each have two tables. One
We have a database that persist our metadata and data. Our metadata is produced
I have two MySQL tables describing data that can be extended into subclasses, one
I have three tables: USER: user_id (pk); username FIELD: field_id (pk); name METADATA: metadata_id

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.