.net Core 2.1.x EntityFramework | DatabaseGeneratedAttribute annotations could not be found

.net entity-framework-core

Question

I'm trying to make use of .Net Entity Framework Core for my application. Relevant portions from .csproj files are:

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0"/>

In my entity classes I'm using the annotations as described in this tutorial. However, my build is failing with errors like:

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

I have included necessary "using" statements in the code. Still the error seems to persist. Any pointers/suggestions what to check for in order to solve this issue will be greatly appreciated.

I'm developing using VS Code on macOS.

Thanks in advance!

1
1
6/7/2018 4:48:37 AM

Popular Answer

After a exploring the API docs for the annotations, I figured that one needs to include the following using statement:

using System.ComponentModel.DataAnnotations.Schema;

The tutorials of .NET Core Entity Framework that I was referring to seems to be misleading as it only had this "using" statement:

using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;

Hopefully this answer will help someone stuck with this issue.

1
6/7/2018 4:57:39 AM


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