开发者

LINQ entity data model generated code error - The type 'DBContexts.Category' already contains a definition for 'ID'

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜