views:

222

answers:

2

I have a database framework where I have two tables. The first table has a single column that is an identity and primary key. The second table contains two columns. One is a varchar primary key and the other is a nullable foreign key to the first table.

When adding the tables to the model I get the following validation error:

Condition cannot be specified for Column member 'DetailsControlSetId' because it is marked with a 'Computed' or 'Identity' StoreGeneratedPattern.

where 'DetailsControlSetId' is the second foreign key reference in the second table.

Steps to reproduce:

1) Create a new .Net 3.5 Client Profile project with Visual Studio 2010 RC.
2) Run scripts below against test database (empty database will do).
3) Create EDMX model, targeting the database created, but opt to not import any tables.
4) Update Model from Database selecting the two tables in the database (DetailsControlSet and Application).
5) Validate the EDMX model.

Table Creation Scripts:

CREATE TABLE [dbo].[DetailsControlSet](
    [DetailsControlSetId] [int] IDENTITY(1,1) NOT NULL,
    CONSTRAINT [PK_DetailsControlSet] PRIMARY KEY CLUSTERED 
    (
        [DetailsControlSetId] ASC
    )
)

GO

CREATE TABLE [dbo].[Application](
    [ApplicationName] [varchar](50) NOT NULL,
    [DetailsControlSetId] [int] NULL,
    CONSTRAINT [PK_Application] PRIMARY KEY CLUSTERED 
    (
        [ApplicationName] ASC
    )
)

GO

ALTER TABLE [dbo].[Application]  WITH CHECK ADD  CONSTRAINT [FK_Application_DetailsControlSet] FOREIGN KEY([DetailsControlSetId])
REFERENCES [dbo].[DetailsControlSet] ([DetailsControlSetId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Application] CHECK CONSTRAINT [FK_Application_DetailsControlSet]
GO
A: 

This article might help, was posted at ADO.NET official team blog

Asad Butt
Unfortunately this is all basic information I already know. I'm not looking for how to setup a basic entity, but rather how to setup this 0..1 to * relationship.
Orion Adrian
Your sample DB script already works correctly for me. I applied it to an empty DB and generated an EF model. No errors.
Craig Stuntz
+2  A: 

Update Now that you've (finally!) posted steps to reproduce this, I can make the error happen on my machine. And diffing the EDMX of the "import everything at first" vs. the "import tables later" models makes the problem obvious. The "working" model has this line:

<Property Name="DetailsControlSetId" Type="int" />

The "error" model has this line:

<Property Name="DetailsControlSetId" Type="int" StoreGeneratedPattern="Identity" />

That's the only substantive difference between the two models.

So to fix this:

  1. Right click EDMX in Solution Explorer.
  2. Open with XML editor.
  3. Delete StoreGeneratedPattern="Identity"
  4. Note that the error immediately goes away.

Having this test case, I was able to do some research. It turns out this is a known bug in VS 2010 beta and was fixed a few days ago.

Craig Stuntz
I knew about the differences in the model and how to fix it manually. I was looking for a root cause. Thank you for the research in finding out that this was a bug.
Orion Adrian