我将以下属性应用于我的linq to sql类:
[Document(MetadataType = typeof(SomeObjectMetadata))]
public partial class SomeObject
{
}
这是元数据代码:
public class SomeObjectMetadata
{
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsKey = true)]
private object ProductId { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsDefault = true)]
private object Name { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Description { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Breadcrumb { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab1Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab2Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab3Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab4Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab5Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Manufacturer { get; set; }
}
索引存储写得很好,但是当我尝试搜索它时,我得到了标题中显示的错误。以下是搜索示例:
var qry = from r in _dbi.Get<SomeObject>()
where r.Description.Like(search)
select r;
在枚举“qry”时,会抛出异常“类必须至少将一个字段定义为默认搜索字段”。
答案 0 :(得分:3)
public class Catalog_ProductMetadata
{
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsKey = true)]
public object ProductId { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsDefault = true)]
public object Name { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Description { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Breadcrumb { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab1Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab2Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab3Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab4Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab5Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Manufacturer { get; set; }
}