【发布时间】:2015-01-08 14:57:36
【问题描述】:
我有 poco 实体,每个父实体都有自己的子外键数据,例如 FK_Owner_User。
public class Listing
{
public int Id{ get; set; }
public int Status { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public virtual User FK_Owner_User{ get; set; }
}
当我得到带有 dbcontext 的父类时,我将它添加到弹性搜索索引中
public ElasticClient ElasticClient
{
get
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(
node,
defaultIndex: "index_name"
);
var client = new ElasticClient(settings);
return client;
}
}
DBContext dbContext = new DBContext();
List<Listing> listings = dbContext.Listings.Where(l => l.Status == 1).Take(10).ToList();
foreach (var listing in listings)
{
ElasticClient.Index(listing)
}
var results = ElasticClient.Search<Listing>(body =>
body.Query(query =>
query.QueryString(qs => qs.Query(productListRequestModel.SearchKey))));
return results.Documents.ToList();
但我看到外键为空。我的问题是当我将 poco 实体添加到弹性客户端索引时,如何填充外键数据?
提前致谢。
单调
【问题讨论】:
-
两个问题:您确定您的列表对象带有来自数据库的用户实例吗?您在查询中使用的 Func 是什么?
-
octavioccl 不,我不确定我现在是否正在检查。第二个答案是我不明白你的问题。我在哪里使用 Func ?非常感谢
-
这个:productListRequestModel.SearchKey
-
@octavioccl 列表对象来自数据库的用户实例,但是当我索引时,它变得空:/
标签: c# entity-framework elasticsearch