2010-03-15 4 views
0

Visual Studio 2008의 .NET Framework 3.5 SP1에서 Entity Framework와 관련된 이상한 문제가 발생합니다. SQL Server에 몇 개의 테이블이있는 데이터베이스를 만든 다음 .edmx Entity Framework 모델과 관련이 있으며 문제가 없습니다. 그런 다음 기존 테이블에 외래 키가 있고 새 .edmx에 추가해야하는 새 테이블을 데이터베이스에 만들었습니다. 그래서 Visual Studio와 모델에서 .edmx를 열었고 "Update Model From Database ..."를 선택했습니다. "추가"탭에서 새 테이블을 보았습니다. 그래서 체크하고 마침을 클릭했습니다. 나는 다음과 같은 텍스트 오류 메시지가 얻을 그러나 : 참고로Entity Framework 모델에 테이블을 추가하려고하면 UpdateModelFromDatabaseException이 발생합니다.

--------------------------- 
Microsoft Visual Studio 
--------------------------- 
An exception of type 'Microsoft.Data.Entity.Design.Model.Commands.UpdateModelFromDatabaseException' occurred while attempting to update from the database. The exception message is: 'Cannot update from the database. Cannot resolve the Name Target for ScalarProperty 'ID <==> CustomerID'.'. 
--------------------------- 
OK 
--------------------------- 

을, 여기에 테이블이 오류에 가장 적절한 것 같다입니다. CustomerPreferences은 .edmx에 이미 있습니다. Diets은 나중에 추가되어 .edmx에 추가하려고하는 테이블입니다.

CREATE TABLE [dbo].[CustomerPreferences](
    [ID] [uniqueidentifier] NOT NULL, 
    [LastUpdatedTime] [datetime] NOT NULL, 
    [LastUpdatedBy] [uniqueidentifier] NOT NULL, 
PRIMARY KEY CLUSTERED 
(
    [ID] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 


CREATE TABLE [dbo].[Diets](
    [ID] [uniqueidentifier] NOT NULL, 
    [CustomerID] [uniqueidentifier] NOT NULL, 
    [Description] [nvarchar](50) NOT NULL, 
    [LastUpdatedTime] [datetime] NOT NULL, 
    [LastUpdatedBy] [uniqueidentifier] NOT NULL, 
PRIMARY KEY CLUSTERED 
(
    [ID] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

GO 

ALTER TABLE [dbo].[Diets] WITH CHECK ADD CONSTRAINT [FK_Diets_CustomerPreferences] FOREIGN KEY([CustomerID]) 
REFERENCES [dbo].[CustomerPreferences] ([ID]) 
GO 

ALTER TABLE [dbo].[Diets] CHECK CONSTRAINT [FK_Diets_CustomerPreferences] 
GO 

이것은 상당히 일반적인 사용 사례처럼 보입니다. 따라서 어디서 잘못 될지 잘 모르겠습니다.

답변

2

Entities 네임 스페이스에 개체를 넣으려고 할 때 문제가 발생했습니다. 분명히 도구와 충돌하는 예약 키워드입니다.

관련 문제