我使用帶有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爲我創建瞭如下表:
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
我該如何解決這個問題?
您是否正在檢查正確的數據庫文件? – ErikEJ
是的,我有一個空的數據庫文件 –
什麼是ef版本?你是否嘗試過屬性Ie。的MaxLength(30)? – ErikEJ