6
I am doubtful in a following rule: I have N Products and N Coins. From this relationship I will have the table Productomoeda:
ProdutoMoeda
Id - ProdutoId - MoedaID - Nome
1 2 1 ProdutoNome + MoedaNome
2 1 1 ProdutoNome + MoedaNome
3 2 2 ProdutoNome + MoedaNome
I also have a correspondent who markets N Productomoeda. However Correspondent also has N Stores that commercializes the N Productomoeda that is linked to the Correspondent. The store can only sell the products that were registered to the Correspondent, since the store depends on the Correspondent also.
Ex: Correspondent Walmart Trades - Kind Product and Card - in USD and BRL Currencies. Store 1 - which belongs to Correspondent Walmart can only register 1 or N products that Walmart markets.
Would it be right to create a Pk for a table that was generated from an N-N and use as a relationship key in another table? I am trying to represent this in EF also but soon when I will relate Correspondent and Productomoeda using Productoccurforming already generates me some errors. I used the same example to map product and it worked, but to use her relationship with product:
ProdutoCorrespondente_ProdutoMoeda_Target_ProdutoCorrespondente_ProdutoMoeda_Source: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical.
The map is like this:
public ProdutoCorrespondenteConfig()
{
HasKey(x => new { x.ProdutoCorrespondenteId, x.ProdutoMoedaId, x.CorrespondenteId });
Property(x => x.ProdutoCorrespondenteId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(t => t.Nome)
.IsRequired()
.HasMaxLength(60);
HasRequired(x => x.ProdutoMoeda)
.WithMany(x => x.ProdutosCorrespondente)
.HasForeignKey(x => x.ProdutoMoedaId);
HasRequired(x => x.Correspondente)
.WithMany(x => x.ProdutosCorrespondente)
.HasForeignKey(x => x.CorrespondenteId);
}
Allan, I found this link from a guy who has a question similar to yours, it doesn’t solve your problem.
http://stackoverflow.com/questions/11754842/how-to-fix-the-number-of-properties-in-the-dependent-and-principal-roles-in-a-r
– pnet