我已經得到了一個數據庫,該數據庫可以與基本的CRUD操作相對應。這很快通過使用.NET 4.5/MVC5和EF6完成。這意味着數據庫優先方法。Nest無法應對EF6/MVC5的大型數據庫模型
新要求:(彈性)搜索。
當爲自定義類創建索引(未鏈接到模型中的其他類)時,一切正常。當我使用有很多外鍵的類時,事情就停止了。該數據庫由100個表格和400多個外鍵組成。
我認爲這個問題可能是循環引用(客戶有n個合同,它有一個客戶的參考,它有一個合同列表,...你得到的圖片)。最終我得到一個OutOfMemory異常,一切都崩潰了。
代碼:
public static Uri node;
public static ConnectionSettings settings;
public static ElasticClient client;
public ActionResult TestIndex()
{
node = new Uri("http://localhost:9200");
settings = new ConnectionSettings(node, defaultIndex: "crudapp");
client = new ElasticClient(settings);
var indexSettings = new IndexSettings();
indexSettings.NumberOfReplicas = 1;
indexSettings.NumberOfShards = 1;
//The next line causes the OutOfMemoryException
client.CreateIndex(c => c.Index("crudapp")
.InitializeUsing(indexSettings)
.AddMapping<Customer>(map => map.MapFromAttributes(maxRecursion: 1)));
foreach (Customer c in db.Customer.Where(a => a.Active == true))
client.Index(c);
return View("Index");
}
我怎麼能告訴巢停止遞歸或不使用特定的對象?
樣品類:
public partial class Customer
{
public Customer()
{
this.CustomerContract = new HashSet<CustomerContract>();
}
public int Customerid { get; set; }
public string CustomerName { get; set; }
public string Description { get; set; }
public bool Active { get; set; }
public virtual ICollection<CustomerContract> CustomerContract { get; set; }
}
public partial class CustomerContract
{
public CustomerContract()
{
this.Host = new HashSet<Host>();
}
public int CustomerContractid { get; set; }
public string CustomerContractName { get; set; }
public string Description { get; set; }
public int CustomerID { get; set; }
public bool Active { get; set; }
public virtual Customer Customer { get; set; }
public virtual ICollection<Host> Host { get; set; }
}