T.Pilvelis T.Pilvelis - 1 year ago 149
ASP.NET (C#) Question

EntityType ' ' has no key defined

So I have been following this tutorial on ASP.NET. I have created a Model and intend on generating a Controller with views, using Entity Framework. However I have been stuck on this error for nearly hours researching causes and its only 2 lines of code and I can't for the life of me understand how I am getting this error.

Link to Tutorial https://mva.microsoft.com/en-US/training-courses/introduction-to-asp-net-mvc-8322?l=Omf358Zy_1604984382
This is all the code I have written
Receiving this message

Answer Source

Here we go:

You should to add the [KEY] attribute for your TaskID like this code:

public class Tasks
 public int TaskID {get;set;}
 public string taskStatus {get;set;}

Hope it helps;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download