我正在使用MVC mobile application service
Entity Framework
我创建了Entity Model
,如此:
public class Regions : EntityData
{
public string Id { get; set; }
public string Name { get; set; }
}
我创建了一个TableController
,因此我通过向:
http://localhost:3000/tables/Regions
这会返回错误说明:
" exceptionMessage":"列名称无效' ID'。\ r \ n无效列名>'版本'。\ r \ n无效列name' CreatedAt'。\ r \ n无效列 name' 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; }
}
因此查询Generated是
'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
中?
答案 0 :(得分:4)
首先,您需要使用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。