1

我有以下具有Content类型属性的实体byte[]

public class Post
{
  [Column(TypeName = "varbinary(max)")]
  [Required]
  public byte[] Content { get; set; }
  
  public string ContentType { get; set; }
}

以及模型构建器中的内容类型:

modelBuilder.Entity<Post>()
    .Property(p => p.ContentType)
    .HasComputedColumnSql("'.html'");

迁移:

migrationBuilder.Sql("CREATE FULLTEXT CATALOG ft_catalog AS DEFAULT", true);
migrationBuilder.Sql(@"CREATE FULLTEXT INDEX ON dbo.Posts([Content] TYPE COLUMN ContentType) KEY INDEX PK_Posts", true);

EF.Functions.FreeText接受一个字符串propertyReference和一个字符串freeText

在这里,我将列“内容”作为我得到的字符串传递The expression passed to the 'propertyReference' parameter of the 'FreeText' method is not a valid reference to a property. The expression should represent a reference to a full-text indexed property on the object referenced in the from clause

IQueryable<DataSets.Post> query = db.Posts;

query = query.Where(k => EF.Functions.FreeText("Content", model.keyword)); 

然后,我环顾四周,找到EF.Property并在 param 上使用它propertyReference,然后我得到了Failed to convert parameter value from a String to a Byte[].

query = query.Where(k => EF.Functions.FreeText(EF.Property<string>(k, "Content"), model.keyword));

以下 SQL 查询对数据库完美运行:

select ID,Title,Description from Posts where FREETEXT(Content,'wolf')
4

0 回答 0