7
I have a problem in an application I am developing, I created the models using the ADO.NET Entity Data Model.
However a specific table is not appearing follows below the script I am using to create the table, it is created and works but is not created template for it.
SQL script I’m using to create the table
-- -----------------------------------------------------
-- Table tb_r_veiculo_adicionais
-- -----------------------------------------------------
CREATE TABLE tb_r_veiculo_adicionais (
veiculo INT NOT NULL,
adicional INT NOT NULL,
PRIMARY KEY (veiculo, adicional),
FOREIGN KEY (veiculo) REFERENCES tb_veiculo (codigo),
FOREIGN KEY (adicional) REFERENCES tb_adicionais (codigo)
)
Below is the error returned
Error 1 Error 3003: Problem in Mapping Fragments Starting at line 528:Given the cardinality of Association End Member tb_veiculo, it should be Mapped to key Columns of the table tb_r_veiculo_adicionais. Either fix the Mapping or change the multiplicity of this end. C: Users Hiago Documents visual studio 2013 Projects Projectprojects Projectprojects
Observing: When deleting EDMX and creating works, only the table template tb_r_veiculo_adicionais
is not generated.
UPDATING: I realized that the problem only occurs when I create the Foreign Keys.
vc defined the code as PK in the tb_vehicle table ?
– Marco Souza
Yes I did, if you want I put the whole SQL.
– Hiago Souza
I don’t really remember now, but I think it’s because of the composite keys
PRIMARY KEY (veiculo, adicional),
try to put an Id in the table asPK
in place of composite key.– Marco Souza
@Marconciliosouza is a requirement I have the composite key, and the Foreign Keys... I can’t change them. Is there any other way?
– Hiago Souza
Behold link
– Marco Souza
Comrade, this is because your table only has fields that are primary or foreign keys.
– Alberto Cláudio Mandlate
Yes, but can you explain to me why he does not accept the table under these conditions? Because they are normalized, they are not out of standard.
– Hiago Souza
Ex: very simple, very simple. Look at the following code: db.TbMusicas.Find(Musi.Idmusica).TbEstilosMusica.Add(styli); Where: db = Entitymodel; Tbmusicas = Table name Mother; Musi.idMusica = Id of the value I look for in the music table; Tbestilosmusica = Name date mother table containing various music styles (Note: I have a daughter table of Tbmusicas that links to the Tbestilosmusica table. This so-called table is called Tbmusicas_styles); styli = is a value found in Tbestilosmusica; It seems a bit confusing, but it’s very simple. I wait for feedback.
– Alberto Cláudio Mandlate
yes more what would be the reason it does not generate an EDMX? Is there anything official about it? is a problem? is not it? am I doing wrong?
– Hiago Souza
I already turned in the job, I just wanted to understand why it didn’t work with the FK
– Hiago Souza
It’s no problem. It’s a class principle in Object-Oriented Programming. And EDMX (or Entity) works based on classes. When a class has only "foreign keys" as probabilities/variables, the way one should work with this class becomes somewhat different.
– Alberto Cláudio Mandlate