Mapping of table without primary key

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
J4N
Posts: 11
Joined: Thu 09 Aug 2012 12:49

Mapping of table without primary key

Post by J4N » Fri 10 Aug 2012 07:54

Hi,

I received from my client a database schema from which I've to import data(and only import).

The problem is that two of its tables doesn't have any primary key.

And with the devart EF connector, I got this error when I'm trying to add one of those table in my edmx file:

Message 4 The table/view 'Catalog1.XXXXXXXX' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.
The problem is that I've just no way of editing it, without having to do something like an half year of validation by the creator/administration/... So I've to use it like this.

Why it isn't possible to have a "virtual" primary key on all fields? Like EF does for MS SQL?

I saw that "Entity Developer" is able to generate it, but it doesn't seems to be able to save this as an edmx file, and then:
1) I can't edit it directly in VS2010
2) I can't put a T4 POCO generator which update my model directly when I got changes

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Mapping of table without primary key

Post by Shalex » Fri 10 Aug 2012 15:23

J4N wrote:Why it isn't possible to have a "virtual" primary key on all fields? Like EF does for MS SQL?
The columns of the table must be not nullable.
J4N wrote:I saw that "Entity Developer" is able to generate it, but it doesn't seems to be able to save this as an edmx file
We strongly recommend using Entity Developer. Why don't you want to employ Devart Entity Model (*.edml)?
J4N wrote:I received from my client a database schema from which I've to import data(and only import).
The problem is that two of its tables doesn't have any primary key.
If the table without PK is needed only for reading, you can implement the following approach:
1. In the database create a table which is the same as the original one but, additionally, has a PK column.
2. Import it to your EF model.
3. Open the model with the XML Editor:
- replace the name of the "false" table with the name of the "original" table (all its occurrences)
- change the name of PK column to ROWID and its type to ROWID (storage part)
- replace the value of ColumnName with ROWID (mapping part)
- change the type of property which corresponds to ROWID column to String (conceptual part)

Post Reply