将目标从 netcoreapp3.0 更改为 netstandard2.1 时缺少 TableAttribute

TableAttribute is missing when change target from netcoreapp3.0 to netstandard2.1

我认为我应该移动我的 class 库以使用 .net 标准 2.1。

table 属性不在 .net 标准 2.1 中吗?

using PWDRS.Core.Entities.Base;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PWDRS.Core.Entities
{
    [Table("ReportType", Schema = "RF")]
    public class RfReportType : EntityBase
    {
        public RfReportType()
        {
        }

The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?)

The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Table' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Schema' could not be found (are you missing a using directive or an assembly reference?)

TableAttribute belongs to the System.ComponentModel.Annotations assembly, which is not part of the .NET Standard. And it seems there are no plans to include it, see this github issue

您需要将它作为一个包安装

Install-Package System.ComponentModel.Annotations -Version 4.6.0

或使用包含 System.ComponentModel.AnnotationsMicrosoft.EntityFrameworkCore 包,如果您需要更多

Install-Package Microsoft.EntityFrameworkCore -Version 3.0.1