我正在使用以下代碼從Lucene索引中獲取結果。如何在IQueryable中爲Lucene使用DbFunctions索引搜索
using (var context = ContentSearchManager.GetIndex("my_profile_index").CreateSearchContext())
{
IQueryable<ProfileSearchItem> query = from profile in context.GetQueryable<ProfileSearchItem>()
where profile.LastName.Equals("Zafar")
let diffYears = DbFunctions.DiffYears(profile.Birthdate, DateTime.Today)
select profile;
return query.ToList();
}
我得到的,因爲DbFunctions.DiffYears
例外:
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
我得到一個記錄,如果我沒有在上面的查詢使用DbFunctions
。我想知道如何在搜索索引時使用DbFunctions
。這只是一個示例查詢,我的唯一目標就是在標題中提到的。
ProfileSearchItem
類:
public class ProfileSearchItem
{
[IndexField("_group")]
public string ItemId { get; set; }
[IndexField("_language")]
public string Language { get; set; }
[IndexField("birthdate")]
public DateTime Birthdate { get; set; }
[IndexField("first_name")]
public string FirstName { get; set; }
[IndexField("last_name")]
public string LastName { get; set; }
}