尝试创建时获取迁移异常<;未映射>;VB.Net中字符串的属性

尝试创建时获取迁移异常<;未映射>;VB.Net中字符串的属性,vb.net,entity-framework-6,entity-framework-migrations,Vb.net,Entity Framework 6,Entity Framework Migrations,我试图在实体中创建非映射字符串属性;但是,迁移无法创建迁移类。但是,它使用整数工作。下面显示了我所测试的内容: Private _testProp As Integer <NotMapped> _ Public Property TestProp() As Integer Get Return _testProp End Get Set(ByVal value As Integer) _testProp = value

我试图在实体中创建非映射字符串属性;但是,迁移无法创建迁移类。但是,它使用整数工作。下面显示了我所测试的内容:

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
这是迁移文件,这是我在向现有实体添加未映射属性时所期望的:

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
当然,这不能成为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.DisableUnicodeFrallentityStrings(Me,modelBuilder)


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

我已经有一段时间遇到这个问题了。但对我来说,它在另一个项目中起作用。尝试创建一个独立的项目,看看它是否能正常工作。有趣的是,我创建了一个新的Vb.Net和C#code first项目,它在这两个项目中都起了作用。这使我认为我所在的项目在DbContext(或其他地方)中配置了导致此问题的内容。我仍然不知道那可能是什么。你是否覆盖了模型创建?如果是这样的话,你能发布你的代码吗?我把它注释掉了,迁移开始工作了。我认为架构师试图做的是确保只有ascii进入数据库。我将建议进行以下更改:modelBuilder.Properties(字符串的)().Configure(Sub(p)p.IsUnicode(False))
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)
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
    MyBase.OnModelCreating(modelBuilder)

    EFHelpers.StringHelper.DisableUnicodeForAllEntityStrings(Me, modelBuilder)

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

End Sub