我有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