2

I have a problem in using Entity data model. I'm unable to add a table in entity model that has no primary key. The same situation is with the table that has composite key.

hotcoder
  • 3,176
  • 10
  • 58
  • 96
  • A table with no primary key is not really a table ... every real, regular table **must have** a primary key.... – marc_s Dec 30 '11 at 09:37

2 Answers2

3

For composite keys sure you are wrong but for the first one How could a framework like Entity Framework could know which row has been updated, deleted while it can not identify the row by a primary key,

even in that tables you can have exact duplicate rows.

For the first one check this question

Community
  • 1
  • 1
Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70
  • So the solution is the third column (primary key)? – hotcoder Dec 30 '11 at 08:45
  • Yeah, or making one of existing columns PK if it applies, for the first case add and ID column with `GUID` type with default `newid()` that can make you free of generating it. – Jahan Zinedine Dec 30 '11 at 08:46
0

1.Change the Table structure and add a Primary Column. Update the Model.

2.Modify the .EDMX file in XML Editor and try adding a New Column under tag for this specific table. (WILL NOT WORK)

3.Instead of creating a new Primary Column to Exiting table, i will make a composite key by involving all the existing columns.(WORKED)

Entity Framework: Adding DataTable with no Primary Key to Entity Model.

Pratap
  • 183
  • 1
  • 2