Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EntityType 'xxx' has no key error

$
0
0

I used the EF Designer from Database to create an Entity Data Model.  I try this code:

public class BillboardContext : DbContext { public DbSet<Billboard> Billboards { get; set; } }
public class BillboardData { public void GetData() 
{
    using (var context = new BillboardContext())
    {
        var bbb = context.Billboards.SqlQuery("SELECT * FROM coherent.billboard").ToList();
       ...
    }
}
The SqlQuery statement gives the "EntityType 'Billboard' has no key" error.

Using the designer in VS 2017 to look at the Billboard entity, it correctly shows that there is a field that is an identity column and that is an "Entity Key".
I have seen suggestions that you should add to the C# code for the table a [Key] descriptor, but that's generated code.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>