Search code examples
c#androidentity-frameworkazurecode-first

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


I am learning using Entity Framework Code First to create my database via Azure Mobile App Service

But I got an error , it looks like

enter image description here

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

And I've already used System.ComponentModel.DataAnnotations.Schema; but it seems not to work .

How can I solve this ?

=====================================================

Finally , I solved it referring to this !! Why can't I reference System.ComponentModel.DataAnnotations?


Solution

  • System.ComponentModel.DataAnnotations is the namespace for ForeignKey as well as Required.

    System.ComponentModel.DataAnnotations.Schema is more specific. For example, if you want to map a field to a specific column name or an entity to a table name.