2

我使用帶有EF代碼優先的SQL Server CE。我有以下域類:在使用EF代碼的SQL Server CE中使用nvarchar數據類型

public class User:BaseEntity 
{ 
    public User() 
    { 
     this.UserForms = new List<UserForm>(); 
     IsAdmin = false; 
     IsActive = true; 
    } 

    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    public string UserName { get; set; } 
    public string Password { get; set; } 
    public bool IsAdmin { get; set; } 
    public bool IsActive { get; set; } 

    public virtual ICollection<UserForm> UserForms { get; set; } 
} 

及以下映射類:

public class UserMap : EntityTypeConfiguration<User> 
{ 
     public UserMap() 
     { 
      // Primary Key 
      this.HasKey(t => t.Id); 

      // Properties 
      this.Property(t => t.FirstName) 
       .HasMaxLength(25) 
       .IsRequired(); 

      this.Property(t => t.LastName) 
       .HasMaxLength(30) 
       .IsRequired(); 

      this.Property(t => t.UserName) 
       .HasMaxLength(10) 
       .IsRequired(); 

      this.Property(t => t.Password) 
       .HasMaxLength(30) 
       .IsRequired(); 
     } 
    } 

EF爲我創建瞭如下表:

enter image description here

EF使用的ntext代替nvarchar使表和當我運行應用程序時,我得到以下錯誤:

The ntext and image data types cannot be used in WHERE, HAVING, GROUP BY, ON, or IN clauses, except when these data types are used with the LIKE or IS NULL predicates

我該如何解決這個問題?

+0

您是否正在檢查正確的數據庫文件? – ErikEJ

+0

是的,我有一個空的數據庫文件 –

+0

什麼是ef版本?你是否嘗試過屬性Ie。的MaxLength(30)? – ErikEJ

回答

0

你試過強制列類型嗎?

this.Property(t => t.FirstName) 
.HasColumnType("nvarchar") 
.HasMaxLength(25) 
.IsRequired(); 
+0

這對我和EF再次創建ntext不起作用 –

相關問題