简体   繁体   中英

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

在此处输入图片说明

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) C# error CS0246 The type or namespace name 'Socket' could not be found (are you missing a using directive or an assembly reference) CS0246: The type or namespace name `T' could not be found. Are you missing a using directive or an assembly reference? in c# error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) CS0246: The type or namespace name 'Employee' could not be found (are you missing a using directive or an assembly reference?)? CS0246 The type or namespace name 'ErrorViewModel' could not be found (are you missing a using directive or an assembly reference?) error CS0246: The type or namespace name 'BannerPosition' could not be found are you missing a using directive or an assembly reference? Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)? error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?) CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM