【问题标题】:EF4 CTP5 - HasColumnType not workingEF4 CTP5 - HasColumnType 不起作用
【发布时间】:2011-06-16 11:16:24
【问题描述】:

我想将我的字符串列之一的默认 nvarchar(4000) 覆盖为 SQL Express 中的文本数据类型。我使用这个代码。

modelBuilder.Entity<Accommodation>()
               .Property(p => p.Information)
               .HasColumnType("text");

但列类型仍为 nvarchar?

我也在这里问http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/a1d84ea9-2f8e-42f0-bb83-ac9f68805d6d?prof=required

【问题讨论】:

  • 您应该考虑使用 nvarchar(max) 而不是 text。 Microsoft 在 SQL Server 2005 和 2008 中保留 text 数据类型以实现向后兼容性,但他们鼓励您使用新的 nvarchar(max) 数据类型。 (msdn.microsoft.com/en-us/library/ms178158(v=SQL.100).aspx)
  • 好点我已将代码更改为 HasColumnType("varchar(max)");它工作正常。谢谢

标签: entity-framework-4 ef4-code-only entity-framework-ctp5


【解决方案1】:

啊,我刚刚想通了,即使我设置了 DropCreateDatabaseIfModelChanges,添加 fluent 映射也不足以强制表再次 dropAndCreate。

我不得不强制它手动更新表格。

【讨论】:

    猜你喜欢
    • 2011-07-15
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 2011-07-02
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    相关资源
    最近更新 更多