Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在可移植类库中为EF Core添加模式注释_C#_.net_Entity Framework Core_Data Annotations_Portable Class Library - Fatal编程技术网

C# 如何在可移植类库中为EF Core添加模式注释

C# 如何在可移植类库中为EF Core添加模式注释,c#,.net,entity-framework-core,data-annotations,portable-class-library,C#,.net,Entity Framework Core,Data Annotations,Portable Class Library,对于我正在进行的一个项目,我们已经编写了一个可移植的PCL,其中包含多个项目之间共享的模型和其他代码。数据访问层位于解决方案中的另一个项目中,但我希望在PCL中使用EF数据注释来匹配我们当前的约定。我在System.ComponentModel.DataAnnotations命名空间中有数据注释,但找不到System.ComponentModel.DataAnnotations.Schema注释 添加了引用,我甚至尝试将EF重新添加到PCL,但我没有任何运气。我读了另一篇文章,他们在同时使用两个

对于我正在进行的一个项目,我们已经编写了一个可移植的PCL,其中包含多个项目之间共享的模型和其他代码。数据访问层位于解决方案中的另一个项目中,但我希望在PCL中使用EF数据注释来匹配我们当前的约定。我在System.ComponentModel.DataAnnotations命名空间中有数据注释,但找不到System.ComponentModel.DataAnnotations.Schema注释

添加了引用,我甚至尝试将EF重新添加到PCL,但我没有任何运气。我读了另一篇文章,他们在同时使用两个名称空间时遇到了一个问题,但我甚至无法让.Schema单独工作

下面是我的代码的示例:

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);
      ...
   }
}

PCL的目标是.NET4.5、.NETCore1.0、UWP和Xamarin平台。在Nuget包管理器中,它显示前面提到的两个名称空间都已添加到项目中,但它们没有显示在解决方案资源管理器中。我尝试过清理项目、构建和恢复包,但仍然一无所获。我看不出这在便携式PCL中不起作用的任何原因,但我是否遗漏了什么?

安装
系统.ComponentModel.Annotations
NuGet软件包是否有帮助?如果没有,它们可能无法用于该类型的项目。

没有,这根本没有帮助。这是目前正在工作的,但是System.ComponentModel.Annotations.Schema是我遇到问题的一个。我也是这么想的,但我想看看是否有其他人也遇到过这件事。您需要将目标设定为至少1.3(无等效PCL配置文件)