Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I eliminate Error 3002?

Say I have the following table definitions in SQL Server 2008:

CREATE TABLE Person (PersonId INT IDENTITY NOT NULL PRIMARY KEY,  Name VARCHAR(50) NOT NULL,  ManyMoreIrrelevantColumns VARCHAR(MAX) NOT NULL)  CREATE TABLE Model (ModelId INT IDENTITY NOT NULL PRIMARY KEY,  ModelName VARCHAR(50) NOT NULL,  Description VARCHAR(200) NULL)  CREATE TABLE ModelScore (ModelId INT NOT NULL REFERENCES Model (ModelId),  Score INT NOT NULL,  Definition VARCHAR(100) NULL,  PRIMARY KEY (ModelId, Score))  CREATE TABLE PersonModelScore (PersonId INT NOT NULL REFERENCES Person (PersonId),  ModelId INT NOT NULL,  Score INT NOT NULL,  PRIMARY KEY (PersonId, ModelId),  FOREIGN KEY (ModelId, Score) REFERENCES ModelScore (ModelId, Score)) 

The idea here is that each Person may have only one ModelScore per Model, but each Person may have a score for any number of defined Models. As far as I can tell, this SQL should enforce these constraints naturally. The ModelScore has a particular "meaning," which is contained in the Definition. Nothing earth-shattering there.

Now, I try translating this into Entity Framework using the designer. After updating the model from the database and doing some editing, I have a Person object, a Model object, and a ModelScore object. PersonModelScore, being a join table, is not an object but rather is included as an association with some other name (let's say ModelScorePersonAssociation). The mapping details for the association are as follows:

 - Association   - Maps to PersonModelScore     - ModelScore         ModelId : Int32       <=>  ModelId : int         Score : Int32         <=>  Score : int     - Person         PersonId : Int32      <=>  PersonId : int 

On the right-hand side, the ModelId and PersonId values have primary key symbols, but the Score value does not.

Upon compilation, I get:

Error 3002: Problem in Mapping Fragment starting at line 5190: Potential runtime violation of table PersonModelScore's keys (PersonModelScore.ModelId, PersonModelScore.PersonId): Columns (PersonModelScore.PersonId, PersonModelScore.ModelId) are mapped to EntitySet ModelScorePersonAssociation's properties (ModelScorePersonAssociation.Person.PersonId, ModelScorePersonAssociation.ModelScore.ModelId) on the conceptual side but they do not form the EntitySet's key properties (ModelScorePersonAssociation.ModelScore.ModelId, ModelScorePersonAssociation.ModelScore.Score, ModelScorePersonAssociation.Person.PersonId).

What have I done wrong in the designer or otherwise, and how can I fix the error?

Many thanks!

like image 857
Andrew Avatar asked May 14 '10 16:05

Andrew


People also ask

How do I fix error code 3002?

In case the 3002 error code is the result of an issue regarding network inconsistency, then this action will flush the DNS IP and also clear the temp data which may have something to do with the error. To perform this action, locate the Power button, turn it off and wait for 30 seconds before powering it back on.

What is Zoom error code 3002?

Error 3002 generally means that the Zoom meeting you are trying to delete is currently running. Try quitting the Zoom application and canceling your meeting after it's closed.


2 Answers

Very late to your question, I had the same issue and discovered that the entity framework designer had identified my "ScoreId" column (relative to your PersonModelScore table) as a primary key column. I changed my setting to false for my ScoreId, and all worked well afterward.

like image 148
Shan Plourde Avatar answered Oct 26 '22 10:10

Shan Plourde


You can set single primary key in the Entity in order to avoid this error.Right Click on the Scalar Properties of the field in the Entity and disable Entity Key if there are many primary keys.

like image 29
Dhandapani Avatar answered Oct 26 '22 12:10

Dhandapani