简体   繁体   中英

Non-Primary Unique Not Joinable in Entity Framework Database First

I'm trying to use EF 6.1.3 to use a Unique constraint for my EF model from Database to EF model. I've examples this done from Code-First, but I can't seem to update my models from the existing database with this schema.

CREATE TABLE [dbo].[Applications]
(
   [ApplicantId] INT NOT NULL IDENTITY, 
   [Name] VARCHAR(50) NOT NULL,
   [StateCode] VARCHAR(2) NOT NULL,
   CONSTRAINT [FK_Applications_ToStates] FOREIGN KEY ([State]) REFERENCES [States]([StateCode]),
)
CREATE TABLE [dbo].[States]
(
   [StateId] INT NOT NULL IDENTITY, 
   [StateCode] VARCHAR(2) NOT NULL  , 
   [StateName] VARCHAR(100) NOT NULL, 
   CONSTRAINT [PK_States] PRIMARY KEY ([StateId]), 
   CONSTRAINT [AK_States_StateCode] UNIQUE ([StateCode]) 
)

I get the following error:

Severity Code Description Project File Line Warning Error 6035: The relationship 'FK_Applications_ToStates' has columns that are not part of the key of the table on the primary side of the relationship. The relationship was excluded.

EF does not support non number-based Primary Keys as far as I know either.

According to the CodePlex of EF, this is an open issue, and the second most requested feature. There is no way to deal with this issue at the time, and I'll have to try and code around it

http://entityframework.codeplex.com/workitem/299

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM