0
votes

So I follow all the steps to create the ADO.NET Entity data model, right click the Model folder, click Add New Item -> ADO.NET Entity Data model -> Generate from Database, and then select the database connection and enter the namespace of my models, and click Finish. However the edmx view looks like this:

enter image description here

I built the solution, still the same. And after the build, the model class is not generated, I can only see:

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

There is no class definition is found here. I checked SQL Server, the table and its data are there. What have I missed?

2
which DB and which EF version do you use? - magicandre1981
@magicandre1981 Microsfot SQL Server Enterprise Edition (64-bit) version 11.0.6020.0, EF 4.0 (Runtime Version v4.0.30319) - Dylan Czenski
ok, looks like use the old ObjectSet API. Don't do this. Use DBContext API (DbSet) by installing EF 6.1.3 via Nuget to your project: nuget.org/packages/EntityFramework/6.1.3, compile it 1 time and now run the wizard to generate model from db - magicandre1981
@magicandre1981 Thanks but I don't think that is the problem since I create another ADO.NET entity model from another table, everything works perfectly. - Dylan Czenski
even if it works for other tries, you should still no longer use the old API. It will be removed from EF-Core 1.0 - magicandre1981

2 Answers

1
votes

The table or view does not have a primary key defined and no valid primary key could be inferred. For this reason, this table or view has been excluded. To use the entity, you will need to review your schema, add the correct keys.

0
votes

If your table has been accidentally removed, add it back to the DBML file and recreate the ADO.NET Entity Data model.