I want to create database tables using Entity framework core from POCO-classes. When I try and add a new scaffold item (option: Razor pages using Entity Framework (CRUD) in VS), there's an error saying: "No suitable constructor found for entity type 'Uri'"
Ive learnt that (amongst others) Uri has to be converted into String in the OnModelCreating method (in the class which inherits from dbContext).
DbContext class:
public class SchoolDbContext : DbContext {
public DbSet<Student> Students { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<Student>()
.Property(t => t.Homepage)
.HasConversion(
v => v.ToString(),
v => new Uri(v));
}
}
Student class:
public class Student {
public int ID { get; set; }
public Uri Homepage {get; set; }
}
I know that the OnModelCreating method is called when the command "Add-Migration Initial" is entered. But since I tried to auto-implement the CRUD classes, I cannot enter the command "Add Migration Initial". Thanks a lot and excuse my poor english..