views:

142

answers:

1

Hi,

I have two tables in my database - Category and Department which both contain the same columns - ID, Name and Code.

I can create a new entity model using the Visual Studio 2008 designer and add the Department and it works fine - I can query the database using LINQ, alls good.

When I update the model and add the Category table, the generated code throws the following errors when I try and compile.

The type 'DBContexts.Category' already contains a definition for 'ID'
The type 'DBContexts.Category' already contains a definition for '_ID'

The type 'DBContexts.Category' already contains a definition for 'Name'
The type 'DBContexts.Category' already contains a definition for '_Name'

A partial method may not have multiple defining declarations

I guess this is something to do with the fact that Department and Category have identical column names - but it doesn't seam to have a problem with the Code column.

Any ideas how I can fix this? I can't really go messing around with the generated code as any changes will be removed if I update the model.

Cheers

+1  A: 

When you update the .dbml file the .designer.cs file is also regenerated BUT if this file is not accessible a new file is generated and added to the project. Since the classes in both files are partial but have the same properties and fields on compile you will get this error.

You can check if you have only one designer generated file for your context. You can do that by right clicking on the name of your class and selecting "Go To Definition" - it will show all files containing definition of your class.

Branislav Abadjimarinov
Nice one! I have a second context for a different database that also has a Category table with ID and Name - somehow I forgot about this. Thanks
Tom