我使用SQL Server CE和EF代码优先。我有以下域类:
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
制作表格,当我运行应用时,我收到以下错误:
ntext和图像数据类型不能在WHERE,HAVING,GROUP中使用 BY,ON或IN子句,除非这些数据类型与。一起使用 LIKE或IS NULL谓词
我该如何解决这个问题?
答案 0 :(得分:0)
你试过强制列类型吗?
this.Property(t => t.FirstName)
.HasColumnType("nvarchar")
.HasMaxLength(25)
.IsRequired();