Reputation: 31
For a project I am working on we have written a Portable PCL to contain models and other code that will be shared between multiple projects. The Data Access Layer is in another project in the solution, but I would like to use EF data annotations in the PCL to match our current convention. I have data annotations in the System.ComponentModel.DataAnnotations namespace working just fine, but System.ComponentModel.DataAnnotations.Schema annotations are not found.
The reference is added, and I have even tried re-adding EF to the PCL, but I haven't had any luck. I read another post where they ran into an issue using both namespaces simultaneously, but I can't even get .Schema working by itself.
Here is an example of what my code looks like:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; //VS shows that this is not being used
namespace Shared.Models.User
{
public class BaseUser
{
[JsonProperty("id")]
[Key]
[Column("UserId", Order = 1)] // ***ColumnAttribute not found
public Guid Id { get; set; }
...
[JsonProperty("fullName")]
[NotMapped] // ***NotMappedAttribute not found
public string FullName => String.Format("{0} {1}", FirstName, LastName);
...
}
}
The PCL is targeting .Net 4.5, .Net Core 1.0, UWP, and Xamarin platforms. In the Nuget Package manager it shows that both of the before-mentioned namespaces have been added to the project, but they do not show up in the solution explorer. I have tried cleaning the project, building, and restoring packages but still nothing. I don't see any reason that this shouldn't work in a Portable PCL, but am I missing something?
Upvotes: 0
Views: 474
Reputation: 30375
Does installing the System.ComponentModel.Annotations
NuGet package help? If not, they may just not be available on that type of project.
Upvotes: 0