Пример #1
0
 public void EntityPersisterWithInstanceTest()
 {
     using (var per = new EntityPersister <Products>("sqlite"))
     {
         Assert.IsNotNull(per);
     }
 }
Пример #2
0
 public void EntityPersisterTest()
 {
     using (var per = new EntityPersister <Products>())
     {
         Assert.IsNotNull(per);
     }
 }
Пример #3
0
 public void GetEntityTypeTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         Assert.AreEqual(typeof(Products), per.GetEntityType());
     }
 }
Пример #4
0
 public void QueryFirstTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         var p = per.Query().FirstOrDefault();
         Assert.IsNotNull(p);
     }
 }
Пример #5
0
 public void CloneTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         var product    = per.Query().FirstOrDefault();
         var newProduct = product.Clone();
     }
 }
Пример #6
0
 public void QueryForConditionTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (var p in per.Query("productname <> '测试'", "productname desc"))
         {
             Console.WriteLine(p.ProductName);
         }
     }
 }
Пример #7
0
 public void QueryTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (var p in per.Query(s => true))
         {
             Console.WriteLine(p.ProductName);
         }
     }
 }
Пример #8
0
 public void QueryToDataTableTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (DataRow row in per.Query("productid <> 0", null, null).Cast <IEntity>().ToDataTable().Rows)
         {
             Console.WriteLine(row.ItemArray.Length);
         }
     }
 }
Пример #9
0
 public void CreateWithManualIdTest()
 {
     using (var per = new EntityPersister <Customers>(instanceName))
     {
         var customer = new Customers {
             CustomerID = Guid.NewGuid().ToString(), CompanyName = "fireasy"
         };
         per.Create(customer);
     }
 }
Пример #10
0
 public void QueryForAnonymousTest1()
 {
     using (var per = new EntityPersister <Orders>(instanceName))
     {
         foreach (var p in per.Query(s => true).Select(s => new { Orderdate = s.OrderDate, Country = s.Customers.Country }))
         {
             Console.WriteLine(p.Country);
         }
     }
 }
Пример #11
0
 public void QueryForAnonymousTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (var p in per.Query(s => true).OrderBy(s => s.ProductName).Select(s => new { Productname = s.ProductName }))
         {
             Console.WriteLine(p.Productname);
         }
     }
 }
Пример #12
0
 public void QueryForMutilOrderTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (var p in per.Query(s => true).OrderBy(s => new { Productid = s.ProductID, Productname = s.ProductName }))
         {
             Console.WriteLine(p.ProductName);
         }
     }
 }
Пример #13
0
 public void QueryForWhereTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (var p in per.Query(s => true).Where(s => (string)s.ProductName == "11"))
         {
             Console.WriteLine(p.ProductName);
         }
     }
 }
Пример #14
0
 public void QuerySerializeTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         //TypeDescriptor.RemoveProvider(new EntityTypeDescriptionProvider(), typeof(EntityObject));
         var p    = per.Query().FirstOrDefault();
         var json = new JsonSerializer();
         Console.WriteLine(json.Serialize(p));
     }
 }
Пример #15
0
 public void CreateTest()
 {
     using (var per = new EntityPersister <Categories>(instanceName))
     {
         var product = new Categories {
             CategoryID = 1, CategoryName = "dd", Description = "aa"
         };
         per.Create(product);
     }
 }
Пример #16
0
 public void QueryForConditionParameterTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         var parameters = new ParameterCollection();
         parameters.Add("name", "测试");
         foreach (var p in per.Query("productname = @name", string.Empty, null, parameters))
         {
             Console.WriteLine(p.ProductName);
         }
     }
 }
Пример #17
0
 public void QueryForSqlTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         foreach (object p in per.Query((SqlCommand)"select productname from products"))
         {
             var f = p.GetType().GetProperty("productname");
             var v = f.GetValue(p, null);
             Console.WriteLine(v);
         }
     }
 }
Пример #18
0
        public void QueryJoinTest()
        {
            using (var per = new EntityPersister <Customers>(instanceName))
            {
                var list = from c in per.Query()
                           join o in per.Query <Orders>().DefaultIfEmpty() on c.CustomerID equals o.CustomerID
                           select new { Contactname = c.ContactName, Orderid = o.OrderID };

                foreach (var s in list)
                {
                    Console.WriteLine(s.Orderid);
                }
            }
        }
Пример #19
0
 public void QueryForPagerTest()
 {
     using (var per = new EntityPersister <Products>(instanceName))
     {
         var pager = new DataPager(2)
         {
             CurrentPageIndex = 1
         };
         foreach (var p in per.Query(s => true).Segment(pager))
         {
             Console.WriteLine(p.ProductName);
         }
     }
 }
Пример #20
0
        public void CreateForIdentityTest()
        {
            using (var per = new EntityPersister <Identitys>(instanceName))
            {
                //Id1 为自增长类型
                //Id2 使用生成器生成
                //Id3 Guid
                var identity = new Identitys();
                per.Create(identity);

                Console.WriteLine(identity.Id1);
                Console.WriteLine(identity.Id2);
                Console.WriteLine(identity.Id3);
            }
        }
Пример #21
0
        public void BatchCreateTest()
        {
            using (var scope = new EntityTransactionScope())
                using (var per = new EntityPersister <Categories>(instanceName))
                {
                    var products = new List <Categories>();
                    for (var i = 0; i < 1000; i++)
                    {
                        products.Add(new Categories {
                            CategoryID = i + 1, CategoryName = "测试" + i, Description = "aa"
                        });
                    }

                    per.BatchCreate(products);

                    scope.Complete();
                }
        }
Пример #22
0
        public SessionFactoryImpl(Configuration cfg, Settings settings)
        {
            this.settings = settings;

            //settings.CacheProvider.Start(null);

            #region Persisters

            entityPersisters = new Dictionary<string, IEntityPersister>();
            foreach (ClassMetadata model in cfg.ClassMappings)
            {
                //string cacheRegion = model.EntityName;
                //ICacheConcurrencyStrategy cache;
                //if (!caches.TryGetValue(cacheRegion, out cache))
                //{
                //    cache =CacheFactory.CreateCache(model.CacheConcurrencyStrategy, cacheRegion, model.IsMutable, settings, properties);
                //    if (cache != null)
                //    {
                //        caches.Add(cacheRegion, cache);
                //    }
                //}

                IEntityPersister cp = new EntityPersister(model, this);  // PersisterFactory.CreateClassPersister(model, cache, this, mapping);
                entityPersisters[model.EntityName] = cp;
            }

            #endregion

            #region Serialization info

            name = settings.SessionFactoryName;

            uuid = Guid.NewGuid().ToString("N");

            SessionFactoryObjectFactory.AddInstance(uuid, name, this);

            #endregion

            currentSessionContext = BuildCurrentSessionContext();
        }
Пример #23
0
        public SessionFactoryImpl(Configuration cfg, Settings settings)
        {
            this.settings = settings;

            //settings.CacheProvider.Start(null);

            #region Persisters

            entityPersisters = new Dictionary <string, IEntityPersister>();
            foreach (ClassMetadata model in cfg.ClassMappings)
            {
                //string cacheRegion = model.EntityName;
                //ICacheConcurrencyStrategy cache;
                //if (!caches.TryGetValue(cacheRegion, out cache))
                //{
                //    cache =CacheFactory.CreateCache(model.CacheConcurrencyStrategy, cacheRegion, model.IsMutable, settings, properties);
                //    if (cache != null)
                //    {
                //        caches.Add(cacheRegion, cache);
                //    }
                //}

                IEntityPersister cp = new EntityPersister(model, this);  // PersisterFactory.CreateClassPersister(model, cache, this, mapping);
                entityPersisters[model.EntityName] = cp;
            }

            #endregion

            #region Serialization info

            name = settings.SessionFactoryName;

            uuid = Guid.NewGuid().ToString("N");

            SessionFactoryObjectFactory.AddInstance(uuid, name, this);

            #endregion

            currentSessionContext = BuildCurrentSessionContext();
        }
Пример #24
0
 internal object GetIdentifier(object entity)
 {
     return(HasCompositeKey
         ? GetIdentifierValues(entity)
         : EntityPersister.GetIdentifier(entity));
 }
Пример #25
0
 protected virtual void DoSaveData(EntityPersister persister, IEntity entity)
 {
     persister.Save(entity);
 }