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!
I found a solution, but I don’t think it is the right one…
I’m selecting the rules again from the DB before trying to add. Is that the correct way?