简体   繁体   English

ASP.NET 样板 - 实体任务需要主键

[英]ASP.NET Boilerplate - Entity Task Requires Primary Key

Im just New to C# and Currently I am trying to learn ASP.NET Single Web Page Application.我只是 C# 的新手,目前我正在尝试学习 ASP.NET 单 Web 页面应用程序。

I'm currently trying to This Tutorial that is provided by ASP.NET Boilerplate, But I am having issues when I am trying to run Add-Migration "Initial"我目前正在尝试 ASP.NET 样板提供的教程,但是当我尝试运行Add-Migration "Initial"时遇到问题

Which says: "The entity type 'Task' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943."其中说: “实体类型'Task'需要定义一个主键。如果您打算使用无键实体类型,请在'OnModelCreating'中调用'HasNoKey'。有关无键实体类型的更多信息,请参阅https:// go.microsoft.com/fwlink/?linkid=2141943。”

实体错误

This is my Tasks.cs这是我的Tasks.cs

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.Timing;

namespace Acme.SimpleTaskApp.Tasks
{
    [Table("AppTasks")]
    public class Task : Entity, IHasCreationTime
    {
        public const int MaxTitleLength = 256;
        public const int MaxDescriptionLength = 64 * 1024; //64KB

        [Required]
        [StringLength(MaxTitleLength)]
        public string Title { get; set; }

        [StringLength(MaxDescriptionLength)]
        public string Description { get; set; }

        public DateTime CreationTime { get; set; }

        public TaskState State { get; set; }

        public Task()
        {
            CreationTime = Clock.Now;
            State = TaskState.Open;
        }

        public Task(string title, string description = null)
            : this()
        {
            Title = title;
            Description = description;
        }
    }

    public enum TaskState : byte
    {
        Open = 0,
        Completed = 1
    }
}

This is my SimpleTaskAppDbContext.cs这是我的SimpleTaskAppDbContext.cs

using Abp.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

namespace Acme.SimpleTaskApp.EntityFrameworkCore
{
    public class SimpleTaskAppDbContext : AbpDbContext
    {
        //Add DbSet properties for your entities...
        public DbSet<Task> Tasks { get; set; }

        public SimpleTaskAppDbContext(DbContextOptions<SimpleTaskAppDbContext> options) 
            : base(options)
        {

        }
    }
}

I don't know what else am I missing, I tried different tutorials that I can explore with CRUD while using asp.net boilerplate.我不知道我还缺少什么,我尝试了不同的教程,我可以在使用 asp.net 样板时使用 CRUD 进行探索。

Your Entity is missing a Primary Key .您的实体缺少Primary Key If you add this to your Entity it should work.如果您将此添加到您的实体中,它应该可以工作。

[Key]
public int Id { get; set; }

Further Information https://docs.microsoft.com/en-us/ef/core/modeling/keys?tabs=data-annotations更多信息https://docs.microsoft.com/en-us/ef/core/modeling/keys?tabs=data-annotations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Boilerplate上的组合主键 - Composive Primary Key on ASP.NET Boilerplate ASP.NET Core MVC 错误 - 实体类型“AspNetUserLogin”需要定义主键 - ASP.NET Core MVC error - The entity type 'AspNetUserLogin' requires a primary key to be defined ASP.NET 核心 Web API - 实体类型'IdentityUserRole<long> ' 需要定义一个主键</long> - ASP.NET Core Web API - The entity type 'IdentityUserRole<long>' requires a primary key to be defined 实体类型“任务”需要定义一个主键 - The entity type "Task" requires a primary key to be defined ASP.NET 样板实体立即提交 - ASP.NET Boilerplate Entity commit immediately ASP.NET MVC 6 - 为实体框架7中的主键分配NOT NULL - ASP.NET MVC 6 - Assigning NOT NULL to the Primary Key in Entity Framework 7 如何在 ASP.NET Boilerplate 中扩展现有实体? - How to extend existing entity in ASP.NET Boilerplate? asp.net 样板错误地将实体保存为已删除 - asp.net boilerplate incorrectly saving entity as deleted 实体框架与 ASP.NET Boilerplate 的一对一关系 - Entity Framework 1-to-1 relationship with ASP.NET Boilerplate .Net迁移实体类型'List<int> ' 需要定义主键</int> - .Net migration The entity type 'List<int>' requires a primary key to be defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM