Column ID occurred more than once in the specification?

I get this error message when I first approach the EF 4.1 code with Sql compact 4. I do not see any model that has an identifier column more than one, so I have no idea why this error occurred. What can cause this error?

Edit: I want to point out a few extra things. Creating a database is a success, but creating a model is not. An exception is thrown from sqlce methods.

+5
source share
2 answers

This issue is related to an SQL query that returns two or more columns with the same name. SQL will handle exact duplicate names in columns without problems, but C # will error everything like this.

An example of a 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 will be duplicated and throw an exception with EF

+5
source

This can also be caused if the transition code is not updated to date. This usually happens when performing Add-Mirgration markup. Instead, run the following command:

Add-Migration <migration-name> -force
+1
source

All Articles