C# 如何忽略默认的EntityData属性?

C# 如何忽略默认的EntityData属性?,c#,asp.net,asp.net-mvc,entity-framework,azure-mobile-services,C#,Asp.net,Asp.net Mvc,Entity Framework,Azure Mobile Services,我正在使用实体框架 我创建了一个实体模型,如下所示: public class Regions : EntityData { public string Id { get; set; } public string Name { get; set; } } 我已经创建了一个TableController,因此我通过向以下对象发出get请求进行查询: http://localhost:3000/tables/Regions 这将返回一个错误,说明: “exceptionMes

我正在使用
实体框架

我创建了一个
实体模型
,如下所示:

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无效列名>'Version'。\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)]
    [Timestamp]
    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
列,因为它们不在我的表
区域中?

首先,您需要使用键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。

首先需要使用键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。

为了澄清,我将隐藏基类属性并将其标记为
[NotMapped]
您可以用我的
区域
类隐藏属性做一个快速示例吗?为了澄清,我将隐藏基类属性并将其标记为
[NotMapped]
你能举一个我的
Regions
类隐藏属性的例子吗?需要注意的是,ITableData提供的字段是支持Azure移动客户端SDK所必需的。版本用于支持ETag。UpdatedAt&Version用于支持脱机同步功能,Deleted用于支持多客户端脱机同步场景中的软删除功能。如果删除这些字段,则无法使用Azure移动客户端SDK。将服务设置为使用“动态模式”将为您将字段添加回数据库。@Adrian谢谢您的评论。事实上,我正在使用Azure移动客户端SDK。你提到这件事真是件好事。如何将服务设置为使用
动态模式
?需要注意的是,ITableData提供的字段是支持Azure移动客户端SDK所必需的。版本用于支持ETag。UpdatedAt&Version用于支持脱机同步功能,Deleted用于支持多客户端脱机同步场景中的软删除功能。如果删除这些字段,则无法使用Azure移动客户端SDK。将服务设置为使用“动态模式”将为您将字段添加回数据库。@Adrian谢谢您的评论。事实上,我正在使用Azure移动客户端SDK。你提到这件事真是件好事。如何将服务设置为使用
动态模式