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

.net-core .net-standard c# entity-framework-core

Question

I figured I should move my class libraries to use .net standard 2.1.

Is table attribute not in .net standard 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?)

1
1
11/19/2019 11:36:13 PM

Accepted Answer

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

You need to install it as a package

Install-Package System.ComponentModel.Annotations -Version 4.6.0

or use Microsoft.EntityFrameworkCore package which includes System.ComponentModel.Annotations, if you need more

Install-Package Microsoft.EntityFrameworkCore -Version 3.0.1
1
11/19/2019 11:30:07 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow