0

如果我有以下课程

public class Order
{

    public virtual ISet<OrderItem> OrderItems { get; set; }

}


public class OrderItem
{

    public virtual Product Product { get; set; }

}

OrderItem 与产品具有一对一的关系。从一个 sql 请求中获得所有这些最有效的方法是什么。

我正在使用休眠标准 api。我如何将订单项和产品添加为连接类型

        using (ITransaction transaction = _session.BeginTransaction())
        {
            try
            {
                Model.Order order = _session
                .CreateCriteria(typeof(Order))
                .Add(Restrictions.Eq("Id", id))
                .CreateAlias("OrderItems", "orderItems", JoinType.xxxx)

                .UniqueResult<Model.Order>();
                transaction.Commit();
                return order;
            }
            catch (HibernateException)
            {
                transaction.Rollback();
                _session.Close();
                _session.Dispose();
                throw;
            }
        }
4

1 回答 1

1
Model.Order order = _session.CreateCriteria(typeof(Order))
    .Add(Restrictions.Eq("Id", id))
    .SetFetchMode("OrderItems", FetchMode.Eager)
    .UniqueResult<Model.Order>();
于 2012-05-14T12:46:19.337 回答