尝试在 VB.Net 中创建 <NotMapped> 属性 的字符串时出现迁移异常

Getting a migration exception when trying to create <NotMapped> property of String in VB.Net

我正在尝试在实体中创建一个非映射字符串 属性;但是,迁移无法创建迁移 class。但是,它使用 Integer 工作。下面是我测试过的:

Private _testProp As Integer
<NotMapped> _
Public Property TestProp() As Integer
    Get
        Return _testProp
    End Get
    Set(ByVal value As Integer)
        _testProp = value
    End Set
End Property

使用 Integer 创建 属性 适用于两个访问器:

PM> Add-Migration Test
Scaffolding migration 'Test'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration Test' again.

这是迁移文件,这是我在将非映射 属性 添加到现有实体时所期望的:

Namespace Migrations
    Public Partial Class Test
        Inherits DbMigration

        Public Overrides Sub Up()
        End Sub

        Public Overrides Sub Down()
        End Sub
   End Class
End Namespace

但是,当我使用带有两个访问器的字符串添加非映射 属性 时(仅使用 get 访问器实际上有效),迁移失败。

Private _testProp As String
<NotMapped> _
Public Property TestProp() As String
    Get
        Return _testProp
    End Get
    Set(ByVal value As String)
        _testProp = value
    End Set
End Property

我得到以下异常:

PM> Add-Migration Test
System.InvalidOperationException: The property 'TestProp' is not a declared property on type 'TestEntity'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.
    at System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.Configure(String structuralTypeName, IEnumerable`1 properties, IEnumerable`1 propertyPath, PrimitivePropertyConfiguration propertyConfiguration)

当然,这不可能是 EntityFramework 代码优先迁移的限制?如果不是,我做错了什么?

更新 这是在 DbContext 的 OnModelCreating 方法中:

Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
    MyBase.OnModelCreating(modelBuilder)

    EFHelpers.StringHelper.DisableUnicodeForAllEntityStrings(Me, modelBuilder)

    TurnOnCascadeDeletes(modelBuilder)
    TurnOffCascadeDeletes(modelBuilder)
    MapTables(modelBuilder)

End Sub

尝试注释掉他的台词: EFHelpers.StringHelper.DisableUnicodeForAllEntityStrings(我,建模师)

它不是框架的一部分,发生在 modelCreating 上,看起来它可能会对字符串做一些事情(它称为字符串助手)。