I am trying to add a scaffold mvc view in .Net Core RC2 but I get the error "There is no entity type ClientsOverviewViewModel on DbContext RNW.Data.ApplicationDbContext" .
With the view I want to display a list of Client. My Client class:
public class Client : Person
{
#region Personal Data
public Nationality Nationality { get; set; }
public Confession Confession { get; set; }
public string SSN { get; set; }
public MaritalStatus MaritalStatus { get; set; }
#endregion
...
}
public class Person
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public Sex Sex { get; set; }
public DateTime Birthday { get; set; }
public Address Birthplace { get; set; }
public Address ResidentialAddress { get; set; }
public string EMail { get; set; }
public string PhoneNumber { get; set; }
}
In the list I want to display 5 properties, which I have put into my ViewModel:
public class ClientsOverviewViewModel
{
[Display(Name = "Nachname")]
public string LastName { get; set; }
[Display(Name = "Vorname")]
public string FirstName { get; set; }
[Display(Name = "Geschlecht")]
public Sex Sex { get; set; }
[Display(Name = "Staatsbürgerschaft")]
public string Nationality { get; set; }
[Display(Name="Geburtsdatum")]
public DateTime? DateOfBirth { get; set; }
}
Also here is my ApplicationDbContext Class:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
I also get the same error, if I try to use Client instead of the viewmodel.
Things I have tried so far:
public DbSet<Client> Clients { get; set; }
public DbSet<Client> Clients { get; set; }
public DbSet<ClientsOverviewViewModel> Clients { get; set; }
public DbSet<ClientsOverviewViewModel> Clients { get; set; }
public DbSet<ClientsOverviewViewModel> Clients { get; set; }
(which shouldn't be necessary but I thought I'll give it a try) I haven't generated a DB yet, might that be an issue? I am also using entity framework core in the version 1.0.0-preview1-final
What I also have tried: I added a TempDbContext which derives from DbContext and just wanted to add the view with Model class Client and Data context class TempDbContext. Then I get the error "The item specified is not the element of a list"
Sadly I was not able to find any blog posts or stackoverflow questions regarding my problem.
Your ViewModel classes must have a key on it. A property named Id
works fine.
The issue I had was EF does not support Generic List (List). Once I changed this I was able to use the scaffolding tools.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.