A column ID occurred more than once in the specification?

扶醉桌前 提交于 2019-12-23 09:14:40

问题


I am getting this error message when using EF 4.1 code first approach with Sql compact 4. I don't see any model who has id column more than one so i have no idea why this error occured. What can cause this error ?

Edit : I want to specifiy few extra things. Database creating is success but model creating is not. And Exception has been thrown from sqlce methods.


回答1:


This issue stems from a SQL query that returns two or more columns that have an identical name. SQL will handle exact duplicate names on columns with no problem but c# will puke errors all over like this one.

example situation:

TableA
  int Id
  varchar Name

TableB
  int Id
  int A_Id
  varchar Name


SELECT A.*,
       B.Name
FROM TableA A

INNER JOIN TableB 
   ON B.A_Id = A.Id

The Id and Name columns would be duplicated and cause an exception with EF




回答2:


This could also be caused when the migration code is not update to date. This usally occurs when the executing the Add-Mirgration muliple times. Run the following command instead:

Add-Migration <migration-name> -force


来源:https://stackoverflow.com/questions/5750742/a-column-id-occurred-more-than-once-in-the-specification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!