我如何消除错误3002? [英] How do I eliminate Error 3002?

查看:1255
本文介绍了我如何消除错误3002?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有如下表定义在SQL Server 2008:

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))

这里的想法是,每个人都可以每个模型只有一个ModelScore,但每个人都可以得分为任意数量的定义模型。据我所知,这SQL自然应该执行这些限制。该ModelScore有一个特殊的意义,这是包含在定义。没有什么惊天动地的存在。

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.

现在,我尝试使用设计师把这种进入实体框架。更新从数据库模型,并做一些编辑后,我有一个Person对象,Model对象和ModelScore对象。 PersonModelScore,是一个连接表,不是一个对象,而是包含与其他名称关联(假设ModelScorePersonAssociation)。是映射的详细信息,为联想如下:

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

在右手侧,所述ModelId和PERSONID值具有主键符号,但是分数值不

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

编译后,我得到的:

错误3002:在映射片段问题起始于行5190:潜在的运行时违反表PersonModelScore的键(PersonModelScore.ModelId,PersonModelScore.PersonId):列(PersonModelScore.PersonId,PersonModelScore.ModelId)映射到EntitySet的ModelScorePersonAssociation的属性(ModelScorePersonAssociation.Person。 PERSONID,ModelScorePersonAssociation.ModelScore.ModelId)的概念的一面,但他们并不构成的EntitySet的关键特性(ModelScorePersonAssociation.ModelScore.ModelId,ModelScorePersonAssociation.ModelScore.Score,ModelScorePersonAssociation.Person.PersonId)。

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?

非常感谢!

推荐答案

很晚了你的问题,我有同样的问题,发现实体框架设计者已经确定了我的ScoreId列(相对于PersonModelScore表)作为主键列。我改变了我的设置为false我ScoreId,一切运作良好之后。

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.

这篇关于我如何消除错误3002?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆