Asp.net core ASP.net core EF core模型创建错误
我对ASP.net核心开发一无所知。我正在后端使用EF Core和Mysql构建一个Web API 我的类图如下所示: 我创建了如下模型类:Asp.net core ASP.net core EF core模型创建错误,asp.net-core,entity-framework-core,asp.net-core-webapi,Asp.net Core,Entity Framework Core,Asp.net Core Webapi,我对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.Ta
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();
}
}
}
使用Microsoft.EntityFrameworkCore;
使用MySQL.Data.EntityFrameworkCore.Extensions;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
名称空间新的Api.Models
{
公共类核心目标
{
public int CoreGoalId{get;set;}
公共字符串标题{get;set;}
公共列表步骤{get;set;}
公共列表好处{get;set;}
公共列表效果{get;set;}
公共列表图像{get;set;}
公共列表子目标{get;set;}
}
公共类子目标
{
公共int子目标{get;set;}
公共字符串标题{get;set;}
公共字符串优先级{get;set;}
公共列表问题{get;set;}
公共CoreGoal CoreGoal{get;set;}
}
公共类WebAPIDataContext:DbContext
{
公共WebAPIDataContext(DbContextOptions)
:基本(选项)
{
}
公共数据库集书籍{get;set;}
公共数据库集CoreGoals{get;set;}
公共数据库集子目标{get;set;}
模型创建时受保护的覆盖无效(ModelBuilder ModelBuilder)
{
modelBuilder.Entity()
.HasMany(b=>b.子目标)
.WithOne();
}
}
}
当我使用Ctrl+F5构建该列表时,它会给我一个错误,即列表不是基本数据类型
我有几个问题:
步骤
,福利
等必须是类,而不是字符串。像子目标
。好的!现在很清楚,我在Django也这样做。谢谢!标量类型的集合(列表
)尚不受支持。谢谢!我来看看