【问题标题】:TableAttribute is missing when change target from netcoreapp3.0 to netstandard2.1将目标从 netcoreapp3.0 更改为 netstandard2.1 时缺少 TableAttribute
【发布时间】:2019-11-19 22:32:37
【问题描述】:

我想我应该移动我的类库以使用 .net 标准 2.1。

表属性不在 .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()
        {
        }

类型或命名空间名称“DataAnnotations”不存在于 命名空间“System.ComponentModel”(您是否缺少程序集 参考?)

找不到类型或命名空间名称“TableAttribute”(是 您缺少 using 指令或程序集引用?)

找不到类型或命名空间名称“表”(您是否缺少 using 指令还是程序集引用?)

找不到类型或命名空间名称“架构”(您是 缺少 using 指令或程序集引用?)

【问题讨论】:

    标签: c# .net-core entity-framework-core .net-standard


    【解决方案1】:

    TableAttribute 属于 System.ComponentModel.Annotations 程序集,它是 .NET Standard 的 is not part。而且似乎没有包含它的计划,请参阅 this github issue

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

    Install-Package System.ComponentModel.Annotations -Version 4.6.0
    

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

    Install-Package Microsoft.EntityFrameworkCore -Version 3.0.1
    

    【讨论】:

    • 它在 CORE 项目中,它与数据库无关,我认为第一个选项是最好的。或者我可以在上下文中定义实体详细信息?试图找出哪个最有意义
    • 这取决于...,我建议第一个,但如果您需要在 CORE 项目中与 EntityFrameworkCore 相关的其他内容,那么同时拥有这两个包没有意义,只使用 Microsoft.EntityFrameworkCore
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    相关资源
    最近更新 更多