public OrderViewModel(Order order)
 {
     Client = order.Client;
     Id = order.Id;
     EndDate = order.EndDate;
     CreatedDate = order.CreatedDate;
     UpdatedDate = order.UpdatedDate;
     Tasks = order.Tasks.Select(x=>new TaskViewModel
     {
         Title = x.Title,
         Id = x.Id,
         Resources = x.Resources.ToList(),
         OrderId = x.OrderId
     }).ToList();
     Title = order.Title;
     Type = order.Type;
     ClientId = order.ClientId ?? 0;
     Resources = order.Resources.ToList();
 }
        private static void CreateOrder(ISession session)
        {
            using (ITransaction tran = session.BeginTransaction())
            {
                try
                {
                    Customer customer = session.Get<Customer>(95);
                    Product product = session.Get<Product>(652);
                    Product product1 = session.Get<Product>(653);

                    Order order = new Order()
                                      {
                                          OrderDate = DateTime.Now,
                                          Comment = "jim Test Create Order111",
                                          customer = customer,
                                          Finished = false,
                                          State = OrderState.Create,
                                          SumMoney = (decimal) 1556.55,
                                      };

                    var od1 = new OrderDetails()
                    {
                        product = product,
                        order = order,
                        Quantity = 10,
                        UnitPrice = (Decimal)22.2
                    };

                    var od2 = new OrderDetails()
                    {
                        product = product1,
                        order = order,
                        Quantity = 20,
                        UnitPrice = (Decimal)32.2
                    };

                    order.details.Add(od1);
                    order.details.Add(od2);

                    session.Save(order);

                    #region 会报警告

                    //Todo:Unable to determine if Entity.OrderDetails with assigned identifier Entity.OrderDetails is transient or detached; querying the database. Use explicit Save() or Update() in session to prevent this.

                    //List<OrderDetails> details = new List<OrderDetails>()
                    //                             {
                    //                                 new OrderDetails()
                    //                                     {
                    //                                         product = product,
                    //                                         order = order,
                    //                                         Quantity = 10,
                    //                                         UnitPrice = (Decimal) 22.2
                    //                                     },
                    //                                       new OrderDetails()
                    //                                     {
                    //                                         product = product1,
                    //                                         order = order,
                    //                                         Quantity = 20,
                    //                                         UnitPrice = (Decimal) 32.2
                    //                                     },
                    //                             };
                    //order.details = details;
                    //session.SaveOrUpdate(order);

                    #endregion

                  /*  var od1 = new OrderDetails()
                                  {
                                      product = product,
                                      order = order,
                                      Quantity = 10,
                                      UnitPrice = (Decimal) 22.2
                                  };

                    session.Save(od1);
                    var od2 = new OrderDetails()
                                  {
                                      product = product1,
                                      order = order,
                                      Quantity = 20,
                                      UnitPrice = (Decimal) 32.2
                                  };
                    session.Save(od2);*/

                    #region 不加这2句就不会多执行2次更新操作

                    /*
                     UPDATE [Order Details]
                     SET    OrderID = 51 /* @p0 #1#
                     WHERE  OrderID = 51 /* @p1 #1#
                            AND ProductID = 650 /* @p2 #1#
                     */

                    //order.details = new List<OrderDetails>();
                    //order.details.Add(od1);
                    //order.details.Add(od2);

                    #endregion

                    tran.Commit();
                }
                catch (Exception)
                {
                    tran.Rollback();

                    throw;
                }
            }
        }