我目前涉及零件目錄項目。NHibernate查詢的問題
爲了給你一些背景信息,我有3個nHib實體零件,應用程序和車輛。
Part.cs
public class Part : Entity
{
public Part()
{
Quality = new PartQuality();
FitmentPosition = new FitmentPosition();
OEPartNumbers = new List<OEPartNumber>();
Applications = new List<Application>();
}
public virtual string Description { get; set; }
[NotNull]
[NotEmpty]
[Pattern(@"\d{4}[-]\d{3}$", RegexOptions.None, "Must be a valid part number")]
[DomainSignature]
public virtual string PartNumber { get; set; }
public virtual PartQuality Quality { get; set; }
public virtual FitmentPosition FitmentPosition { get; set; }
public virtual string Notes { get; set; }
public virtual string VehicleComments { get; set; }
public virtual string Image { get; set; }
public virtual IList<OEPartNumber> OEPartNumbers { get; set; }
public virtual IList<Application> Applications { get; set; }
}
Application.cs
public class Application : Entity
{
[DomainSignature]
public virtual string Name { get; set; }
public virtual DateTime DateFrom { get; set; }
public virtual DateTime DateTo { get; set; }
// Fuel
public virtual bool Diesel { get; set; }
public virtual bool Petrol { get; set; }
// Transmission
public virtual bool Manual { get; set; }
public virtual bool Automatic { get; set; }
public virtual bool SemiAutomatic { get; set; }
// Air Con
public virtual bool WithAC { get; set; }
public virtual bool WithOutAC { get; set; }
// Body
public virtual bool Hatchback { get; set; }
public virtual bool Saloon { get; set; }
public virtual bool Convertable { get; set; }
public virtual bool Estate { get; set; }
public virtual bool Coupe { get; set; }
public virtual bool Van { get; set; }
// Number of Doors
public virtual bool Doors2 { get; set; }
public virtual bool Doors3 { get; set; }
public virtual bool Doors4 { get; set; }
public virtual bool Doors5 { get; set; }
[DomainSignature]
public virtual Part Part { get; set; }
public virtual IList<Vehicle> Vehicles { get; set; }
}
Vehicle.cs
public class Vehicle : Entity
{
public virtual string Make { get; set; }
public virtual string Model { get; set; }
public virtual string Type { get; set; }
public virtual string Engine { get; set; }
public virtual DateTime ProductionStart { get; set; }
public virtual DateTime ProductionEnd { get; set; }
public virtual IList<Application> Applications { get; set; }
}
可以看出,部分可以有很多應用程序和應用程序可以有許多車輛。
我想拉回所有車輛的列表,使用品牌,型號,類型和引擎,但也突出顯示,如果任何車輛鏈接到給定的應用程序。我打算使用具有make,model,type,engine和islinked(bool)屬性的DTO。
我可以把過濾的車輛拉回來,但我有問題確定車輛是否與應用程序鏈接。這將是很好,如果我可以做以下
IsLinked = ((Vehicle.Applications.Count(x => x.Name == _name) > 0)
但它不編譯。有任何想法嗎??
問候
豐富
你不能做Vehicle.Applications.Contains(vehicle)嗎? :) – Skurmedel