scaffolding (database first) EF Core table with no primary key - entity-framework-core

I am using EF core 2.0 and using scaffolding reverse engineering database first to generate models.
some of tables does not have any primary key and EF Unable to generate entity type for table.
Any advice how can I do this other then adding manually.

So far either Entity Framework or Entity Framework Core does not support generating table from EF/EF Core model class without primary key.
But this is a requested feature in Entity Framework Core. Here is the details about it:
Allow code generation for tables without a primary key

You could upgrade to EF core 3.0 which is currently in preview, that is now possible.

Related

Can EF7 Create non-clustered primary key?

In EF6.1 we had to use migration to get a non-clustered PK.
Does anyone know if EF7 have first-class support for non-clustered PK or do we have to use work arounds again?
You might have your answer now, since EF Core 1.0 (formerly EF7) is baked. But just in case you didn't know or if any one else comes across this thread...
EF Core does have support within the mssql provider.
https://github.com/aspnet/EntityFramework/issues/5790
You can do it in Entity Framework Core Code First by ovveriding OnModelCreating in DbContext
p.HasKey(b => b.ColumnId).ForSqlServerIsClustered(false);
This will generate migration like this:
table.PrimaryKey("PK_Columns", x => x.ColumnId)
.Annotation("SqlServer:Clustered", false);

entity framework generates ugly foreign keys names

When I generated the model of the database using ADO.NET Entity Data Model, the generated model had ugly foreign keys names. I tried to change the names in SQL Server Management Studio and then I generated the model again but it did not adopt the new names of the foreign keys.
So please could anyone help me to solve this problem?
With automatic migration the name is assigned by EF.
With manual migration you can specify the name in AddForeignKey method. Here the specifications
https://msdn.microsoft.com/en-us/library/system.data.entity.migrations.dbmigration.addforeignkey(v=vs.113).aspx
EDIT
During automatic migration the EF build the name with this logic
FK_<sourceTable>_<targetTable>_<sourceFieldsList>
See EF framework source code ForeignKeyOperation.cs property DefaultName

Is their a way to generate POCOs with DataAnnotation attributes applied to the POCOs?

I'm using EF5.
Does a visual studio template exists which can generate POCOs having appropriate attributes applied to them from the DataAnnotations namespace (like Key and Foreign Key)
I can generate POCOs using the EF 5.x DBContext Generator which utilizes an existing Entity Data Model, but then I have to manually go setup the Keys and Foreign keys.
For a larger data model this is a pain!
This worked perfectly for me - http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d

Can't generate EF model correctly with Devart dotConnect for PostgreSQL product

I have problem when creating Entity Framework model from an existing PostgreSQL database with the Devart dotConnect for PostgreSQL product.
This product offer 2 ways of generating EF model from a database and neither seems to work.
When using an ADO.Net Entity data Model with this Devart provider, the tables list appear empty in the wizard when generating model from database.
When using the Devart Entity Model, the table list appear correctly in the wizard and model is generated but all navigations properties are missing and all not nullable fields are generated as entity keys.
Anyone has experience with this product and can confirm me if I'm facing bugs or if I'm not using it correctly?
Thanks
Etienne
After some investigation it seems that the database user in PostgreSQL I was using to access dabatase from Entity Framework was missing the INHERIT attribute. Without this attribute the user was not inheriting from his group privileges that give him access to database objects...
The behavior differences between the 2 ways of generating EF model is due to the fact that obtaining the metadata in ADO.NET Entity Data Model Wizard is implemented mainly through the 'information_schema', while in Entity Developer it is implemented with 'pg_catalog'.

Does entity framework 3.5 support composite keys made up from foreign keys?

We have a table which has a composite primary key consisting of two foreign keys. I know that this should work on EF 4.0 but we get an update exception when trying to insert the referenced entities when using EF 3.5.
I tried to look for confirmation whether or not EF 3.5 supports this but the answer seems to always be "Yes, EF 4.0 supports this".
So I'm asking here:
Does entity framework 3.5 support composite keys made up from foreign keys?