Dear All,
I am currently involved in a parts catalogue project.
To give you some background info, I have 3 nHib Entities Part, Application and Vehicle.
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; }
}
It can be seen that a part can have many applications and an application can have many vehicles.
I am trying to pull back a list of all vehicles, using Make, Model, Type and Engine, but also highlight if any of the vehicles are linked to a given Application. I was going to use a DTO with properties of make, model, type, engine and islinked(bool).
I can pull back the filtered vehicles fine, but I am having the issue of identifying whether the vehicle is linked to an application or not. It would be nice if I could do the following
IsLinked = ((Vehicle.Applications.Count(x => x.Name == _name) > 0)
But it doesn't compile. Any Ideas??
Regards
Rich