如何忽略默认的EntityData属性?

我正在使用Entity Framework创建MVC mobile application service

我创建了一个Entity Model如下所示:

 public class Regions : EntityData { public string Id { get; set; } public string Name { get; set; } } 

我已经创建了一个TableController所以我通过发出一个get请求来查询:

 http://localhost:3000/tables/Regions 

这会返回错误说:

“exceptionMessage”:“无效的列名’Id’。\ r \ n无效的列名>’版本’。\ r \ n无效的列名’CreatedAt’。\ r \ n无效的列名’UpdatedAt’。”,

查看EntityData类,我可以看到这些是EntityData类的属性:

 public abstract class EntityData : ITableData { protected EntityData(); [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Index(IsClustered = true)] [TableColumn(TableColumnType.CreatedAt)] public DateTimeOffset? CreatedAt { get; set; } [TableColumn(TableColumnType.Deleted)] public bool Deleted { get; set; } [Key] [TableColumn(TableColumnType.Id)] public string Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Computed)] [TableColumn(TableColumnType.UpdatedAt)] public DateTimeOffset? UpdatedAt { get; set; } [TableColumn(TableColumnType.Version)] 1541547078 public byte[] Version { get; set; } } 

所以生成的查询是

 'SELECT [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name], [Extent1].[Version] AS [Version], [Extent1].[CreatedAt] AS [CreatedAt], [Extent1].[UpdatedAt] AS [UpdatedAt], [Extent1].[Deleted] AS [Deleted] FROM [dbo].[Region] AS [Extent1]'' 

这显然是查询失败的原因。

是否可以排除这些默认的EntityData列,因为它们不在我的表Regions

首先,您需要使用key new隐藏基类属性:

 public new DateTimeOffset? CreatedAt { get; set; } 

然后添加属性[NotMapped]

 [NotMapped] public new DateTimeOffset? CreatedAt { get; set; } 

最后结果:

 public class Regions : EntityData { public string Id { get; set; } public string Name { get; set; } [NotMapped] public new DateTimeOffset? CreatedAt { get; set; } [NotMapped] public new DateTimeOffset? UpdatedAt { get; set; } [NotMapped] public new byte[] Version { get; set; } } 

在这种情况下,我不知道你想如何对待id。 如果需要隐藏基类属性,请在键入之前添加new。