我对ASP.net核心开发完全陌生。我正在后端使用EF-Core和Mysql构建Web API。
我创建了如下的模型类:
using Microsoft.EntityFrameworkCore;
using MySQL.Data.EntityFrameworkCore.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace New_Api.Models
{
public class CoreGoal
{
public int CoreGoalId { get; set; }
public string Title { get; set; }
public List<string> Steps { get; set; }
public List<string> Benefits { get; set; }
public List<string> Effect { get; set; }
public List<string> Images { get; set; }
public List<SubGoal> SubGoals { get; set; }
}
public class SubGoal
{
public int SubGoalId { get; set; }
public string Title { get; set; }
public string Priority { get; set; }
public List<string> Issues { get; set; }
public CoreGoal CoreGoal { get; set; }
}
public class WebAPIDataContext : DbContext
{
public WebAPIDataContext(DbContextOptions<WebAPIDataContext> options)
: base(options)
{
}
public DbSet<Book> Books { get; set; }
public DbSet<CoreGoal> CoreGoals { get; set; }
public DbSet<SubGoal> SubGoals { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CoreGoal>()
.HasMany(b => b.SubGoals)
.WithOne();
}
}
}
当我使用Ctrl + F5构建它时,它给出了List不是原始数据类型的错误。
我有几个问题: