我有3個對象Vehicle,Car和MotorCycle。 Vehicle是Car和MotorCycle的抽象基類。RavenDb,關於abstcts類實現的屬性的查詢
public abstract class Vehicle
{
public String Color {get;set};
public Int Price {get;set};
public DateTime ReleaseDate {get;set};
}
public class Car : Vehicle
{
public Int EnginePower {get;set};
public Int TrunkSpace {get;set};
public bool GearBoxType {get;set};
public Int Seats {get;set};
}
public class MotorCycle : Vehicle
{
public Int EnginePower {get;set};
public String Type{get;set};
}
我想在RavenDb的同一份文件中存儲所有車輛(汽車,摩托車......)。所以我使用這個慣例,它的工作原理:
documentStore.Conventions.FindTypeTagName =
type => type.IsSubclassOf(typeof(Vehicle)) ?
DocumentConvention.DefaultTypeTagName(typeof(Vehicle)) :
DocumentConvention.DefaultTypeTagName(type);
現在我想爲我的所有車輛的請求做索引。但我想請求車輛屬性和實現(汽車,MotorCycle)屬性。請求
實施例I將:
- 所有車輛用顏色= 「紅色」,EnginePower> 100
- 所有車輛用顏色= 「紅色」,EnginePower> 100,座椅= 5
- 具有type =「滑板車」
- 等所有車輛....
而結果只有一個採集驅動車輛類型,以便通過RealeaseDate的。 如何在C#和linq中執行這樣的查詢?
只是一個簡短的提示,如果您想通過EnginePower查詢,您需要將該屬性移動到基類並將其包含在索引中。 – 2014-11-21 18:14:17
感謝您的回覆,但我不想移動Property EnginePower。我可以從我的單個文檔集合(多種類型)查詢RavenDb studio中的兒童類屬性。在C#中不可能做到這一點? – k4st0r42 2014-11-22 16:52:46
然後你需要使用一個接口並建立索引。在RavenDB中要記住的事情就是一切都是索引,你從來不會像數據庫那樣真正「查詢」它。 – 2014-11-23 20:47:57