ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,553 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Environment: Net Core 6, Visual Studio Community 2022 (64 bit), WIndows 11 ======== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ======== Browser Error: InvalidOperationException: The property 'Course.Enrollments' is of an interface type ('ICollection'). If it is a navigation, manually configure the relationship for this property by casting it to a mapped entity type. Otherwise, ignore the property using the [NotMapped] attribute or 'Ignore' in 'OnModelCreating'.
using System;
using System.Collections;
using System.Collections.Generic;
namespace ContosoUniverstiyEmbed.Models
{
public class Student
{
public int ID { get; set; }
public string? LastName { get; set; }
public string? FirstMidName { get; set; }
public DateTime? EnrollmentDate { get; set; }
public ICollection? Enrollments { get; set; }
}
}
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace ContosoUniverstiyEmbed.Models
{
public class Course
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int CourseID { get; set; }
public string? Title { get; set; }
public int? Credits { get; set; }
public ICollection? Enrollments { get; set; }
}
}
namespace ContosoUniverstiyEmbed.Models
{
public enum Grade
{
A, B, C, D, F
}
public class Enrollment
{
public int EnrollmentID { get; set; }
public int CourseID { get; set; }
public int StudentID { get; set; }
public Grade? Grade { get; set; }
public Course? Course { get; set; }
public Student? Student { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ContosoUniverstiyEmbed.Models;
namespace ContosoUniverstiyEmbed.Data
{
public class ContosoUniverstiyEmbedContext : DbContext
{
public ContosoUniverstiyEmbedContext (DbContextOptions<ContosoUniverstiyEmbedContext> options)
: base(options)
{
}
public DbSet<ContosoUniverstiyEmbed.Models.Student> Student { get; set; } = default!;
public DbSet<ContosoUniverstiyEmbed.Models.Course> Course { get; set; }
public DbSet<ContosoUniverstiyEmbed.Models.Enrollment> Enrollment { get; set; }
}
}
The collection type is missing.
public ICollection<Enrollment>? Enrollments { get; set; }