nhibernate选择标准格式

时间:2013-06-25 13:26:32

标签: c# nhibernate

我们正在使用nhibernater,我们有这个对象

    namespace DTO_AM
   {
/// <summary>
/// This is a list of all airplane types in our fleet
/// </summary>
[DataContract]
public class Airplane : ParentType
{
    /// <summary>
    /// The aircraft's model
    /// </summary>
    [DataMember]
    public virtual string AirplaneType { get; set; }
    /// <summary>
    /// How many passengers can sit on this plane
    /// </summary>
    [DataMember]
    public virtual int PassengerCapacity { get; set; }
    /// <summary>
    /// Fuel capacity in gallons
    /// </summary>
    [DataMember]
    public virtual int FuelCapacity { get; set; }
    /// <summary>
    /// the base maximum speed for this aircraft without any enhancements
    /// </summary>
    [DataMember]
    public virtual int MaxSpeed { get; set; }
    /// <summary>
    /// The company that manufactures this model
    /// </summary>
    [DataMember]
    public virtual string Manufacturer { get; set; }
    /// <summary>
    /// The aircraft's first flight
    /// </summary>
    [DataMember]
    public virtual DateTime DateCommissioned { get; set; }
    /// <summary>
    /// The airline that owns the aircraft
    /// </summary>
    [DataMember]
    public virtual string OwnedCompany { get; set; }
    /// <summary>
    /// The list of engines owned by this aircraft
    /// </summary>
    [DataMember]
    public virtual IList<Engines> EnginesOwned { get; set; }

这使得所有飞机成功。

            public static IList<Airplane> getAllAirplanes()
    {
        ISession session = SessionManager.GetSession();


        var planes = session.CreateCriteria<Airplane>().List();
        IList<Airplane> airplanes = new List<Airplane>();
        foreach (Airplane plane in planes)
        {
            airplanes.Add(plane);
        }

        return airplanes;

    }

我需要根据制造商和飞机类型购买一架飞机。根据我的研究,我应该能够为我的CreateCriteria添加限制,但这不会编译。

我应该能够做到这一点。

            public static Airplane getAirplane(string Manufacturer, string AirplaneType)
    {
        ISession session = SessionManager.GetSession();

        var airplane = session.CreateCriteria<Airplane>().Add(Restriction.Eq("Manufacturer", Manufacturer)).
                                                       Add(Restriction.Eq("AirplaneType", AirplaneType)).UniqueResult();
      return airplane;       
    }

但这不会编译。有什么问题?

0 个答案:

没有答案